first commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package org.openautonomousconnection.luascript.runtime;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.openautonomousconnection.luascript.events.LuaEventDispatcher;
|
||||
import org.openautonomousconnection.luascript.hosts.HostServices;
|
||||
import org.openautonomousconnection.luascript.security.LuaExecutionPolicy;
|
||||
import org.openautonomousconnection.luascript.security.LuaSecurityManager;
|
||||
import org.openautonomousconnection.luascript.tables.console.ConsoleTable;
|
||||
import org.openautonomousconnection.luascript.tables.DomTable;
|
||||
import org.openautonomousconnection.luascript.tables.EventsTable;
|
||||
import org.openautonomousconnection.luascript.tables.UiTable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* High-level entry point for wiring Lua tables + bootstrap + event routing.
|
||||
*/
|
||||
public final class LuaRuntime implements AutoCloseable {
|
||||
|
||||
private final Globals globals;
|
||||
private final HostServices services;
|
||||
|
||||
private final LuaSecurityManager securityManager;
|
||||
private final LuaEventDispatcher dispatcher;
|
||||
private final LuaEventRouter eventRouter;
|
||||
|
||||
public LuaRuntime(Globals globals, HostServices services) {
|
||||
this(globals, services, LuaExecutionPolicy.uiDefault());
|
||||
}
|
||||
|
||||
public LuaRuntime(Globals globals, HostServices services, LuaExecutionPolicy policy) {
|
||||
this.globals = Objects.requireNonNull(globals, "globals");
|
||||
this.services = Objects.requireNonNull(services, "services");
|
||||
Objects.requireNonNull(policy, "policy");
|
||||
|
||||
this.securityManager = new LuaSecurityManager();
|
||||
this.dispatcher = new LuaEventDispatcher(globals, securityManager, policy);
|
||||
this.eventRouter = new LuaEventRouter(dispatcher);
|
||||
}
|
||||
|
||||
public Globals globals() {
|
||||
return globals;
|
||||
}
|
||||
|
||||
public LuaEventRouter eventRouter() {
|
||||
return eventRouter;
|
||||
}
|
||||
|
||||
public void installStdTables(boolean overwrite) {
|
||||
new UiTable().inject(globals, services, overwrite);
|
||||
new ConsoleTable().inject(globals, services, overwrite);
|
||||
new EventsTable(dispatcher).inject(globals, services, overwrite);
|
||||
new DomTable().inject(globals, services, overwrite);
|
||||
}
|
||||
|
||||
public void bootstrapFromDom() {
|
||||
LuaScriptBootstrap.bootstrap(globals, services, dispatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
securityManager.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user