Reading and writing C struct from built-in lua

I would like to embed lua to allow scripts in my C ++ application. In particular, I have two structures that I would like to pass as arguments for this lua function. One of them will be available for reading only, the other for reading / writing. The following are simplified examples of these structures:

struct inData
{
    int x;
    int y;
    //many other fields follow
};

struct outData
{
    int a;
    double b;
    //other fields follow
};

Both of these structures are created in C ++ code and will be processed there both before and after calling the lua functions. How to pass these structures to the lua function so that the function can do such things:

if(inData.x > 5) then outData.a = 1 end

and does the outData instance really save the changes after returning from the lua function?

+3
source share
3 answers

Lua, C Lua.

+1

userdata outdata *. , . , /. , outdata , userdata ( ), __index, .

, , , . , Lua C ( ++), void * s.

0
source

Source: https://habr.com/ru/post/1764574/


All Articles