AP_Scripting: allow loading moduels from ROMFS

This commit is contained in:
Iampete1 authored and Andrew Tridgell committed 2024-02-27 10:17:43 +11:00
1 parent ac769014c4
commit b7dd432409
4 files changed
+36

No files matched your search

+27
View File
@@ -920,6 +920,33 @@ int lua_get_current_ref()
return scripting->get_current_ref();
}
// This is used when loading modules with require, lua must only look in enabled directory's
const char* lua_get_modules_path()
{
#define LUA_PATH_ROMFS "@ROMFS/scripts/modules/?.lua;" "@ROMFS/scripts/modules/?/init.lua"
#define LUA_PATH_SCRIPTS LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua"
uint16_t dir_disable = AP_Scripting::get_singleton()->get_disabled_dir();
dir_disable &= uint16_t(AP_Scripting::SCR_DIR::SCRIPTS) | uint16_t(AP_Scripting::SCR_DIR::ROMFS);
if (dir_disable == 0) {
// Both directory's are enabled, return both, ROMFS takes priority
return LUA_PATH_ROMFS ";" LUA_PATH_SCRIPTS;
}
if ((dir_disable & uint16_t(AP_Scripting::SCR_DIR::SCRIPTS)) == 0) {
// Only scripts enabled
return LUA_PATH_SCRIPTS;
}
if ((dir_disable & uint16_t(AP_Scripting::SCR_DIR::ROMFS)) == 0) {
// Only ROMFS enabled
return LUA_PATH_ROMFS;
}
// Nothing enabled?
return "";
}
// Simple print to GCS or over CAN
int lua_print(lua_State *L) {
// Only support a single argument