we're sandboxing and loading the log function from textual into LUA!!!!!!! :D

This commit is contained in:
2025-10-27 13:09:10 +11:00
parent 0fe3a7e234
commit 48b6e535a2
2 changed files with 32 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
from textual_window import Window
from textual.widgets import RichLog
from textual import work
from lupa import LuaRuntime, lua51
import os, json, asyncio
@@ -16,6 +17,8 @@ class PluginLoader(Window):
start_open=True
)
self.lua_runtime = lua51.LuaRuntime()
@work
async def find_plugins(self):
log = self.query_one(RichLog)
@@ -68,8 +71,27 @@ class PluginLoader(Window):
continue
log.write(f"[b green]FOUND[/] {plugin_json['name']} ({plugin_json['version']})")
for lua_file in os.listdir(os.path.join(plugin_folder, "lua")):
lua_file_path = os.path.join(plugin_folder, f"lua/{lua_file}")
with open(lua_file_path, "r") as f:
code = f.read()
sandbox = self.lua_runtime.eval("{}")
setfenv = self.lua_runtime.eval("setfenv")
sandbox.print = self.log #self.lua_runtime.globals().print
sandbox.math = self.lua_runtime.globals().math
sandbox.string = self.lua_runtime.globals().string
setfenv(0, sandbox)
executed_code = self.lua_runtime.execute(code)
if executed_code.init:
executed_code.init()
if executed_code.main:
self.run_worker(thread=True, work=executed_code.main)
plugin_paths.append(plugin_folder)
log.write("\n[d]Window will automatically close in 5 seconds.[/]")

View File

@@ -0,0 +1,9 @@
local plugin = {}
function plugin.init()
end
function plugin.main()
end
return plugin