I'm looking for a solution to bind a C variable (integer, double, normal C string or similar) to Lua. Lua should be able to modify this variable (in C context). I'm not looking for a solution to call a C function at all (from Lua to get the reference to that variable). I also do not want to use any external library for this (Lua API will do fine). I have seen that LuaBridge solve this (existing project using this: https://github.com/Malaxiz/Third/blob/network/Fifth/CGame.cpp#L240), but as I said, no external libraries and definitely not C++.
Example of use:
C code
typedef struct Instance {
int test; /* The variable I want to link to Lua (and be able to modify it)*/
} Instance;
int main() {
lua_State* L = lua_open();
Instance instance;
instance.test = 5;
/* ... */
}
And in Lua:
instance.test = instance.test + 5
print(instance.test) -- Should be 10
Back to C:
int main() {
...
printf("%i\n", instance.test); /* Should be 10 here too */
}
Is there a workaround for this?