new scripting functionality
* dofiles functions to run all scripts inside a directory * new style option ! that evaluates its value from a lua code
This commit is contained in:
parent
243bd3a930
commit
fae2cc6481
|
@ -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'
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
if not UIWindow then dofile 'uiwindow' end
|
||||
|
||||
UIMessageBox = extends(UIWindow)
|
||||
|
||||
MessageBoxOk = 1
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue