Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED
- From: "Robert G. Jakabosky" <bobby@xxxxxxxxxxxxxxx>
- To: luajit@xxxxxxxxxxxxx
- Date: Thu, 21 Jun 2012 07:28:48 -0700
On Thursday 21, Patrick Masotta wrote:
> good question...
> so far I run into trouble sending ints to the C side; I have done so
> on a C log function (like printf but for GUI) that receives variable # of
> parameters. The string pointers where passed ok but the integers weren't.
> So far I've solved the thing with a trick
> ffi.C.LOG(l, string.format(...))
> buy why your question? why I couldn't pass the integers??
The reason for my question about passing the limit to the C side is that
seeing code that uses strcpy/strcat makes me nervous, since it is very easy to
overflow the buffer.
Ah, I wasn't thinking about the issue of passing Lua numbers to vararg
functions. I had just thrown that example together. The FFI docs say you
have to cast the Lua number to an int, since LuaJIT doesn't know that the
function wants an int instead of a double.
-- Example from the FFI docs:
ffi.C.printf("integer value: %d\n", ffi.new("int", x))
--
Robert G. Jakabosky
Other related posts:
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Peter Cawley
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Robert G. Jakabosky
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Michal Kottman
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Paulo Matias
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Robert G. Jakabosky
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Robert G. Jakabosky
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED - Robert G. Jakabosky
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Claire Lewis
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Claire Lewis
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Javier Guerra Giraldez
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Coda Highland
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Adam Strzelecki
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Coda Highland
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Geoff Leyland
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Geoff Leyland
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Dimiter 'malkia' Stanev
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Claire Lewis
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Sean Conner
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- dcharno
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Craig Barnes
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Adam Strzelecki
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » RE: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- William Adams