13
0

Lua Script Sandbox - GUI part

This commit is contained in:
Robin Gareus 2017-08-09 16:00:35 +02:00
parent 0191a9c4c2
commit d0553753af
2 changed files with 6 additions and 3 deletions

View File

@ -967,6 +967,7 @@ LuaInstance::~LuaInstance ()
void
LuaInstance::init ()
{
lua.sandbox (false);
lua.do_command (
"function ScriptManager ()"
" local self = { scripts = {}, instances = {}, icons = {} }"
@ -984,7 +985,7 @@ LuaInstance::init ()
" assert(type(f) == 'function', 'Factory is a not a function')"
" assert(type(a) == 'table' or type(a) == 'nil', 'Given argument is invalid')"
" self.scripts[i] = { ['n'] = n, ['s'] = s, ['f'] = f, ['a'] = a, ['c'] = c }"
" local env = _ENV; env.f = nil env.debug = nil os.exit = nil require = nil dofile = nil loadfile = nil package = nil"
" local env = _ENV; env.f = nil env.io = nil"
" self.instances[i] = load (string.dump(f, true), nil, nil, env)(a)"
" if type(c) == 'function' then"
" self.icons[i] = load (string.dump(c, true), nil, nil, env)(a)"
@ -1085,7 +1086,6 @@ LuaInstance::init ()
" manager = ScriptManager ()"
" ScriptManager = nil"
);
lua_State* L = lua.getState();
try {
@ -1482,6 +1482,7 @@ LuaInstance::register_lua_slot (const std::string& name, const std::string& scri
try {
LuaState l;
l.Print.connect (&_lua_print);
l.sandbox (true);
lua_State* L = l.getState();
register_hooks (L);
l.do_command ("function ardour () end");
@ -1688,6 +1689,7 @@ void
LuaCallback::init (void)
{
lua.Print.connect (&_lua_print);
lua.sandbox (false);
lua.do_command (
"function ScriptManager ()"
@ -1699,7 +1701,7 @@ LuaCallback::init (void)
" assert(type(f) == 'function', 'Factory is a not a function')"
" assert(type(a) == 'table' or type(a) == 'nil', 'Given argument is invalid')"
" self.script = { ['n'] = n, ['s'] = s, ['f'] = f, ['a'] = a }"
" local env = _ENV; env.f = nil env.debug = nil os.exit = nil require = nil dofile = nil loadfile = nil package = nil"
" local env = _ENV; env.f = nil env.io = nil"
" self.instance = load (string.dump(f, true), nil, nil, env)(a)"
" end"
""

View File

@ -199,6 +199,7 @@ void LuaWindow::reinit_lua ()
delete lua;
lua = new LuaState();
lua->Print.connect (sigc::mem_fun (*this, &LuaWindow::append_text));
lua->sandbox (false);
lua_State* L = lua->getState();
LuaInstance::register_classes (L);