diff --git a/modules/core_lib/core_lib.otmod b/modules/core_lib/core_lib.otmod index 0845338d..c0d7cc20 100644 --- a/modules/core_lib/core_lib.otmod +++ b/modules/core_lib/core_lib.otmod @@ -8,14 +8,8 @@ Module reloadable: false @onLoad: | - dofile 'ext/table' - dofile 'ext/string' - dofile 'ext/os' - - dofile 'math/point' - dofile 'math/size' - dofile 'math/color' - dofile 'math/rect' + dofiles 'ext' + dofiles 'math' dofile 'const' dofile 'util' @@ -25,23 +19,6 @@ Module dofile 'mouse' dofile 'string' - dofile 'ui/effects' - dofile 'ui/radiogroup' - dofile 'ui/tooltip' - - dofile 'widgets/uiwidget' - dofile 'widgets/uibutton' - dofile 'widgets/uilabel' - dofile 'widgets/uicheckbox' - dofile 'widgets/uicombobox' - dofile 'widgets/uispinbox' - dofile 'widgets/uiprogressbar' - dofile 'widgets/uitabbar' - dofile 'widgets/uipopupmenu' - dofile 'widgets/uiwindow' - dofile 'widgets/uimessagebox' - dofile 'widgets/uisplitter' - dofile 'widgets/uiscrollbar' - dofile 'widgets/uiscrollarea' - dofile 'widgets/uiresizeborder' + dofiles 'ui' + dofiles 'widgets' diff --git a/modules/core_lib/widgets/uimessagebox.lua b/modules/core_lib/widgets/uimessagebox.lua index b9f232aa..2b59f0d3 100644 --- a/modules/core_lib/widgets/uimessagebox.lua +++ b/modules/core_lib/widgets/uimessagebox.lua @@ -1,3 +1,5 @@ +if not UIWindow then dofile 'uiwindow' end + UIMessageBox = extends(UIWindow) MessageBoxOk = 1 diff --git a/src/framework/luascript/luainterface.cpp b/src/framework/luascript/luainterface.cpp index 384132c3..d0c69bc2 100644 --- a/src/framework/luascript/luainterface.cpp +++ b/src/framework/luascript/luainterface.cpp @@ -536,6 +536,24 @@ int LuaInterface::luaScriptRunner(lua_State* L) } } +int LuaInterface::luaScriptsRunner(lua_State* L) +{ + std::string directory = g_lua.popString(); + + for(const std::string& fileName : g_resources.listDirectoryFiles(directory)) { + if(!boost::ends_with(fileName, ".lua")) + continue; + + try { + g_lua.loadScript(directory + "/" + fileName); + g_lua.call(0, 0); + } catch(LuaException& e) { + logError("failed to load script file '", fileName, "' :'", e.what()); + } + } + return 0; +} + int LuaInterface::luaErrorHandler(lua_State* L) { // pops the error message @@ -614,6 +632,10 @@ void LuaInterface::createLuaState() // replace dofile pushCFunction(&LuaInterface::luaScriptRunner); setGlobal("dofile"); + + // dofiles + pushCFunction(&LuaInterface::luaScriptsRunner); + setGlobal("dofiles"); } void LuaInterface::closeLuaState() diff --git a/src/framework/luascript/luainterface.h b/src/framework/luascript/luainterface.h index 9e900b72..e731ed65 100644 --- a/src/framework/luascript/luainterface.h +++ b/src/framework/luascript/luainterface.h @@ -188,6 +188,8 @@ private: static int luaScriptLoader(lua_State* L); /// Run scripts requested by lua 'dofile' static int luaScriptRunner(lua_State* L); + /// Run scripts requested by lua 'dofiles' + static int luaScriptsRunner(lua_State* L); /// Handle lua errors from safeCall static int luaErrorHandler(lua_State* L); /// Handle bound cpp functions callbacks diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index d53ba62c..effdb586 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -461,6 +461,20 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode) m_loadingStyle = true; try { + // translate ! style tags + for(const OTMLNodePtr& node : styleNode->children()) { + if(node->tag()[0] == '!') { + std::string tag = node->tag().substr(1); + std::string code = Fw::formatString("tostring(%s)", node->value().c_str()); + std::string origin = "@" + node->source() + "[" + node->tag() + "]"; + g_lua.evaluateExpression(code, origin); + std::string value = g_lua.popString(); + + node->setTag(tag); + node->setValue(value); + } + } + onStyleApply(styleNode->tag(), styleNode); callLuaField("onStyleApply", styleNode->tag(), styleNode); @@ -471,7 +485,6 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode) focus(); } m_firstOnStyle = false; - } catch(Exception& e) { logError("Failed to apply style to widget '", m_id, "' style: ", e.what()); }