we're sandboxing and loading the log function from textual into LUA!!!!!!! :D
This commit is contained in:
@@ -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)
|
||||
@@ -67,9 +70,28 @@ class PluginLoader(Window):
|
||||
log.write(f"[d]Ignoring {plugin_folder} because of error: {e}.[/]")
|
||||
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.[/]")
|
||||
|
||||
Reference in New Issue
Block a user