39 lines
1.4 KiB
Java
39 lines
1.4 KiB
Java
|
|
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
|
||
|
|
import org.luaj.vm2.Globals;
|
||
|
|
import org.openautonomousconnection.luascript.utils.LuaGlobalsFactory;
|
||
|
|
import org.openautonomousconnection.luascript.events.LuaEventDispatcher;
|
||
|
|
import org.openautonomousconnection.luascript.events.UiEvent;
|
||
|
|
import org.openautonomousconnection.luascript.hosts.HostServices;
|
||
|
|
import org.openautonomousconnection.luascript.runtime.LuaRuntime;
|
||
|
|
import org.openautonomousconnection.luascript.security.LuaSecurityManager;
|
||
|
|
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
public class Main {
|
||
|
|
|
||
|
|
public static void main(String[] args) {
|
||
|
|
Globals g = LuaGlobalsFactory.create(new LuaGlobalsFactory.Options()
|
||
|
|
.sandbox(true)
|
||
|
|
.enableDebug(false));
|
||
|
|
|
||
|
|
HostServices services = HostServices.builder().build();
|
||
|
|
LuaRuntime runtime = new LuaRuntime(g, services);
|
||
|
|
|
||
|
|
try (LuaSecurityManager security = new LuaSecurityManager()) {
|
||
|
|
LuaEventDispatcher dispatcher = new LuaEventDispatcher(g);
|
||
|
|
|
||
|
|
g.load("""
|
||
|
|
function onBtn(ctx)
|
||
|
|
net.core.get("/index.html", function(resp)
|
||
|
|
-- resp.status, resp.contentType, resp.body, resp.headers
|
||
|
|
end)
|
||
|
|
end
|
||
|
|
""", "page.lua").call();
|
||
|
|
Event
|
||
|
|
dispatcher.bind("btn1", "click", "onBtn");
|
||
|
|
dispatcher.dispatch(new UiEvent("btn1", "click", Map.of()));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|