Prepare for explicit Lua Sandboxing (API update) 1/4

This commit is contained in:
Robin Gareus 2023-10-04 01:21:34 +02:00
parent 7e7337aa61
commit 7c10a54334
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 9 additions and 3 deletions

View File

@ -27,7 +27,7 @@
class LIBLUA_API LuaState {
public:
LuaState();
LuaState (bool sandbox = true, bool rt_safe = false);
LuaState(lua_State *ls);
~LuaState();
@ -36,7 +36,7 @@ public:
void collect_garbage () const;
void collect_garbage_step (int debt = 0);
void tweak_rt_gc ();
void sandbox (bool rt_safe = false);
void sandbox (bool rt_safe);
sigc::signal<void,std::string> Print;

View File

@ -26,11 +26,16 @@ static int panic (lua_State *L) {
return 0; /* return to Lua to abort */
}
LuaState::LuaState()
LuaState::LuaState(bool enable_sandbox, bool rt_safe)
: L (luaL_newstate ())
{
assert (L);
init ();
if (enable_sandbox) {
sandbox (rt_safe);
} else {
do_command ("os.exit = nil os.setlocale = nil");
}
}
LuaState::LuaState(lua_State *ls)
@ -38,6 +43,7 @@ LuaState::LuaState(lua_State *ls)
{
assert (L);
init ();
sandbox (true);
}
LuaState::~LuaState() {