I want to pass a list containing numbers from Lua to C and access it in C. How can I do it?
Suppose I have the following Table:
x = {1, 2, 3, 9, 5, 6}
I want to send it to C and store this table in array in C.
I sent it using:
quicksort(x)
where quicksort is the function I have defined in C.
How can I access the x in C?
The table you pass to the function will be on the function’s stack. You can index it by using
lua_getfieldorlua_gettable.Traversing the table with
lua_next, you can populate your array in C if you need to; although, for an array, simply iterating from 1 to#tshould suffice.Some example utility code (untested):