Yeah, that's exactly what I'm aiming for. I want Lua to fail, not my application to crash.
I managed to "sandbox" each loaded script/component like our plugins but in a single lua_State. I still need to test this some more though...
It's also possible to attach Lua data (tables and whatever) to userdata (C++ objects). The Lua data always stays in Lua and will be garbage collected by Lua, it may linger after the C++ object has been deallocated and the Lua reference is set to NULL as long as Lua has a reference to it.
Now I just need to figure out how attach the loaded script to userdata the same way as a script can attach other data to a C++ object. Right now a loaded script is attached to a table to achieve the sandboxing effect, but it should be attached to the C++ object/userdata itself.
Xoft, I sometimes see you mentioning the overhead of bridging between Lua and C++. According to this thread just calling simple C++ functions is actually really fast: http://lua.2524044.n2.nabble.com/Is-it-s...50170.html
Stuff seems to work, I can call both C++ functions and functions declared in Lua that are attached to a component. Interestingly enough the script is stuck in the scope of the component, this means I cannot easily call global functions. I need to store a reference to the global table (_G) in order to call functions on it.
Just printing text turns into _G.print("blabla") as well as table functions _G.table.insert(t, 1) .... that's pretty inconvenient.
I am now thinking of adding a mechanism that first checks if a function exists in the global table and call it, or otherwise call the function in the component table (or other way around) but I'm not sure how much of an impact this will have on performance...
I managed to "sandbox" each loaded script/component like our plugins but in a single lua_State. I still need to test this some more though...
It's also possible to attach Lua data (tables and whatever) to userdata (C++ objects). The Lua data always stays in Lua and will be garbage collected by Lua, it may linger after the C++ object has been deallocated and the Lua reference is set to NULL as long as Lua has a reference to it.
Now I just need to figure out how attach the loaded script to userdata the same way as a script can attach other data to a C++ object. Right now a loaded script is attached to a table to achieve the sandboxing effect, but it should be attached to the C++ object/userdata itself.
Xoft, I sometimes see you mentioning the overhead of bridging between Lua and C++. According to this thread just calling simple C++ functions is actually really fast: http://lua.2524044.n2.nabble.com/Is-it-s...50170.html
Stuff seems to work, I can call both C++ functions and functions declared in Lua that are attached to a component. Interestingly enough the script is stuck in the scope of the component, this means I cannot easily call global functions. I need to store a reference to the global table (_G) in order to call functions on it.
Just printing text turns into _G.print("blabla") as well as table functions _G.table.insert(t, 1) .... that's pretty inconvenient.
I am now thinking of adding a mechanism that first checks if a function exists in the global table and call it, or otherwise call the function in the component table (or other way around) but I'm not sure how much of an impact this will have on performance...