Search code examples
clualuajit

Passing C struct pointer to lua script


I would like to know is there a way to pass a struct pointer to a lua script, and reach it's members from lua without copy (for read and write purposes).

So, for example is it possible to overwrite a member of a c struct directly through of its pointer?

(I am using luajit)


Solution

  • Seeing as you have tagged this for luajit, you can combine the light userdata (as mentioned by others) with FFI for direct struct member access, see the tutorial here: http://luajit.org/ext_ffi_tutorial.html