Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED

  • From: Patrick Masotta <masottaus@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 21 Jun 2012 08:04:53 -0700 (PDT)

I agree the patch is not "necessary" but it adds the beauty of simmetry and 
simplicity


local  var_01       = ffi.new("char[50]", "default value for var_01" )
local  var_01_desc  = ffi.new("char[?]", 0, "This is the var_01 
description\nvar_01 is used for...\nvar_01 allowed values are...");

the former chunk does not create aux variables and looks far better than

local  var_01 = ffi.new("char[50]", "default value for var_01" )
local str_01 = "This is the var_01 description\nvar_01 is used for...\nvar_01 
allowed values are...");
local var_01_desc = ffi.new('char [?]', #str_01+1, str_01)

mostly if you are a LUA newcomer and/or you have to declare 100s of 
variables....

(just my opinion)


> 
> But I'd say the patch is not really necessary, the Lua
> wrapper/helper is a better option.  I'd be surprised if
> LuaJIT doesn't do a good job of optimizing that away anyway
> (be easy enough to check a dump output to check).
> 
> - Claire
> 
> 
>

Other related posts: