lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Florian Berger wrote:
Can I pass a Lua table pointer to a C function? I would like to use Lua
table in C in read-only way.

Hi Floru,

Always use the C API; you never need to use lua_topointer.

You should use the lua_rawgeti function.
See section 3.13 and 3.11 of the manual.
http://www.lua.org/manual/5.0/manual.html#3.13

If the C API cramps your style, or if you need to do something like an FFT on the array data, then you can put your array of numbers, or a pointer to it, inside a userdata. You can give the userdata a metatable with index/newindex events to get/set elements of your array from Lua scripts. This would be a good exercise for those who want to learn about userdata.

- Peter