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 06:15:07 -0700 (PDT)

this brings another question...
you say that if I have let say:

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

I cannot alter from C var_01 if the C side receive var_01's pointer?
why not?



> 
> It's Lua, not LUA. Regarding the "Lua string creation" -
> what you have
> to understand is that the Lua string is already created -
> all string
> literals are created as constants when the code is compiled.
> This
> means that when you call this:
> 
> local buf = ffi.new("char[?]",0, "HELLO WORLD")
> 
> The string "HELLO WORLD" is already somewhere in memory.
> What FFI does
> is that it copies this string over a 0-byte char array
> (overwriting
> memory you should not be writing to).
> 
> 

Other related posts: