Share Array between lua and C

Viewed 7573

I have really Googled this question but I never really got an solution.

I want to share an Array between C and Lua, for performance I will avoid copying Arrays to and from Lua.

So I want to pass a pointer to the Array from C to Lua. And then from Lua I want to set/modify values in this array directly.


Example in C code

I want to define my array

int mydata[] = {1,2,3,4} 

set it global to access it from Lua with the name mydata.


In Lua

I want to change the values like this

mydata[3] = 9

and when I return to C, mydata[3] is 9 because it is a pointer to the array.

How is this possible?

1 Answers
Related