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

  • From: "Claire Lewis" <claire_lewis@xxxxxxxxxxx>
  • To: <luajit@xxxxxxxxxxxxx>
  • Date: Fri, 22 Jun 2012 00:50:00 +0930


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

It is certainly simpler; I'm not sure it really adds "simmetry" to anything; if anything it is less orthogonal because other VLA cases require the length.

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

Creation of (local) variables is probably not a huge worry in LuaJIT; it'll likely deal with that. It's the creation of values that can be expensive, and it already creates a string value either way.

In any case, I meant that it would be just as easy to wrap it within Lua, as suggested by someone earlier in the thread.

Here's another possible way to do that (untested):

function cstring(str)
   return #str+1, str
end

...

local  var_01 = ffi.new("char[?]", cstring "default value for var_01" )


- Claire.


Other related posts: