!7 concept ScriptClass > Named {} cmodule ChatBotFrontend > DynChatBotFrontend { Set scriptRefs = syncSet(); transient L scripts; transient CRUD scriptsCRUD; start { scriptsCRUD = new CRUD(cc, ScriptClass); thread "Load Scripts" { while (dm_booting()) sleepSeconds(0.1); loadScripts(); } } afterVisualize { addTab(tabs, "Scripts", scriptsCRUD.visualize()); } void loadScripts { new L scripts; for (S ref : (LS) collect name(main list(cc, ScriptClass))) pcall { LS l = splitAtSlash(ref); if (l(l) != 3) continue with print("Can't load script: " + ref); S mod = dm_require(first(l) + "/" + second(l)); Class c = dm_getClassInModuleRealm(mod, "main$" + last(l)); if (c == null) continue with print("Couldn't find class: " + ref); O o = nu(c); forwardSwappableFunctionsToObject(o, module(), 'setBotName, 'getBotName); scripts.add(o); print("Got script: " + o); } this.scripts = scripts; } @Override S answer_other(S s) null { fOr (virtual CruddieScript script : scripts) pcall { try S a = (S) call(script, 'answer, s); } } // API void addScript(S moduleLibID, S shortClassName) { if (uniq_trueIfNew(cc, ScriptClass, name := addPrefix("#", moduleLibID) + "/" + assertIdentifier(shortClassName))) loadScripts(); } }