Switched to JavaFX and added builtin Support
This commit is contained in:
@@ -12,14 +12,21 @@ import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Bootstrap that:
|
||||
* 1) Executes all Lua scripts found in DOM
|
||||
* * 2) Scans DOM for on:* handlers and binds them automatically.
|
||||
* 1) Executes ALL scripts found in DOM as Lua: <script> ... or <script src="...">
|
||||
* 2) Scans DOM for on:* handlers and binds them automatically.
|
||||
*/
|
||||
public final class LuaScriptBootstrap {
|
||||
|
||||
private LuaScriptBootstrap() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstraps Lua from DOM.
|
||||
*
|
||||
* @param globals globals
|
||||
* @param services host services
|
||||
* @param dispatcher event dispatcher
|
||||
*/
|
||||
public static void bootstrap(Globals globals, HostServices services, LuaEventDispatcher dispatcher) {
|
||||
Objects.requireNonNull(globals, "globals");
|
||||
Objects.requireNonNull(services, "services");
|
||||
@@ -41,20 +48,16 @@ public final class LuaScriptBootstrap {
|
||||
Map<String, String> attrs = dom.getAttributes(elementId);
|
||||
if (attrs == null) continue;
|
||||
|
||||
String type = safeLower(attrs.getOrDefault("type", ""));
|
||||
String src = attrs.get("src");
|
||||
|
||||
boolean isLuaByType = "lua".equals(type) || "text/lua".equals(type) || "application/lua".equals(type);
|
||||
if (!isLuaByType) continue; // IMPORTANT: only run scripts explicitly marked as Lua
|
||||
|
||||
boolean hasSrc = src != null && !src.trim().isEmpty();
|
||||
|
||||
if (hasSrc) {
|
||||
String path = src.trim();
|
||||
try {
|
||||
String code = resources.readText(path);
|
||||
LuaScriptExecutor.execute(globals, code, path);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to load lua script src='" + path + "': " + ex.getMessage(), ex);
|
||||
throw new IllegalStateException("Failed to load script src='" + path + "': " + ex.getMessage(), ex);
|
||||
}
|
||||
} else {
|
||||
String inline = dom.getTextContent(elementId);
|
||||
|
||||
Reference in New Issue
Block a user