From beaa069082146c46f7d56f2fe647cadee66f4690 Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Mon, 8 Oct 2018 22:28:34 -0700 Subject: [PATCH] AP_Scripting: Disable lua coroutines --- libraries/AP_Scripting/AP_Scripting.cpp | 18 ++++++++++++++++-- libraries/AP_Scripting/lua/src/linit.c | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/libraries/AP_Scripting/AP_Scripting.cpp b/libraries/AP_Scripting/AP_Scripting.cpp index 49a67ed630..92ff67ca05 100644 --- a/libraries/AP_Scripting/AP_Scripting.cpp +++ b/libraries/AP_Scripting/AP_Scripting.cpp @@ -25,7 +25,7 @@ #define SCRIPTING_STACK_MIN_SIZE 2048 #if !defined(SCRIPTING_STACK_SIZE) - #define SCRIPTING_STACK_SIZE 8192 + #define SCRIPTING_STACK_SIZE 16384 #endif // !defined(SCRIPTING_STACK_SIZE) #if !defined(SCRIPTING_STACK_MAX_SIZE) @@ -80,7 +80,21 @@ void AP_Scripting::thread(void) { luaL_openlibs(state); load_lua_bindings(state); - luaL_loadstring(state, "gcs.send_text(string.format(\"1 + 2 = %d\", 1+2))"); +// luaL_loadstring(state, "gcs.send_text(string.format(\"1 + 2 = %d\", 1+2))"); + + // load the sandbox creation function + if (luaL_dofile(state, "sandbox.lua")) { + gcs().send_text(MAV_SEVERITY_CRITICAL, "SFATAL: %s", lua_tostring(state, -1)); + return; + } + + luaL_loadfile(state, "test.lua"); + lua_getglobal(state, "get_sandbox_env"); //find the sandbox creation function + if (lua_pcall(state, 0, LUA_MULTRET, 0)) { + gcs().send_text(MAV_SEVERITY_CRITICAL, "SFATAL: %s", lua_tostring(state, -1)); + return; + } + lua_setupvalue(state, -2, 1); while (true) { hal.scheduler->delay(1000); diff --git a/libraries/AP_Scripting/lua/src/linit.c b/libraries/AP_Scripting/lua/src/linit.c index 49ef2f3bf5..9369de77c0 100644 --- a/libraries/AP_Scripting/lua/src/linit.c +++ b/libraries/AP_Scripting/lua/src/linit.c @@ -42,7 +42,7 @@ static const luaL_Reg loadedlibs[] = { {"_G", luaopen_base}, {LUA_LOADLIBNAME, luaopen_package}, - {LUA_COLIBNAME, luaopen_coroutine}, +// {LUA_COLIBNAME, luaopen_coroutine}, {LUA_TABLIBNAME, luaopen_table}, // {LUA_IOLIBNAME, luaopen_io}, {LUA_OSLIBNAME, luaopen_os},