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
|
reloadable: false
|
||||||
|
|
||||||
@onLoad: |
|
@onLoad: |
|
||||||
dofile 'ext/table'
|
dofiles 'ext'
|
||||||
dofile 'ext/string'
|
dofiles 'math'
|
||||||
dofile 'ext/os'
|
|
||||||
|
|
||||||
dofile 'math/point'
|
|
||||||
dofile 'math/size'
|
|
||||||
dofile 'math/color'
|
|
||||||
dofile 'math/rect'
|
|
||||||
|
|
||||||
dofile 'const'
|
dofile 'const'
|
||||||
dofile 'util'
|
dofile 'util'
|
||||||
|
@ -25,23 +19,6 @@ Module
|
||||||
dofile 'mouse'
|
dofile 'mouse'
|
||||||
dofile 'string'
|
dofile 'string'
|
||||||
|
|
||||||
dofile 'ui/effects'
|
dofiles 'ui'
|
||||||
dofile 'ui/radiogroup'
|
dofiles 'widgets'
|
||||||
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'
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
if not UIWindow then dofile 'uiwindow' end
|
||||||
|
|
||||||
UIMessageBox = extends(UIWindow)
|
UIMessageBox = extends(UIWindow)
|
||||||
|
|
||||||
MessageBoxOk = 1
|
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)
|
int LuaInterface::luaErrorHandler(lua_State* L)
|
||||||
{
|
{
|
||||||
// pops the error message
|
// pops the error message
|
||||||
|
@ -614,6 +632,10 @@ void LuaInterface::createLuaState()
|
||||||
// replace dofile
|
// replace dofile
|
||||||
pushCFunction(&LuaInterface::luaScriptRunner);
|
pushCFunction(&LuaInterface::luaScriptRunner);
|
||||||
setGlobal("dofile");
|
setGlobal("dofile");
|
||||||
|
|
||||||
|
// dofiles
|
||||||
|
pushCFunction(&LuaInterface::luaScriptsRunner);
|
||||||
|
setGlobal("dofiles");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaInterface::closeLuaState()
|
void LuaInterface::closeLuaState()
|
||||||
|
|
|
@ -188,6 +188,8 @@ private:
|
||||||
static int luaScriptLoader(lua_State* L);
|
static int luaScriptLoader(lua_State* L);
|
||||||
/// Run scripts requested by lua 'dofile'
|
/// Run scripts requested by lua 'dofile'
|
||||||
static int luaScriptRunner(lua_State* L);
|
static int luaScriptRunner(lua_State* L);
|
||||||
|
/// Run scripts requested by lua 'dofiles'
|
||||||
|
static int luaScriptsRunner(lua_State* L);
|
||||||
/// Handle lua errors from safeCall
|
/// Handle lua errors from safeCall
|
||||||
static int luaErrorHandler(lua_State* L);
|
static int luaErrorHandler(lua_State* L);
|
||||||
/// Handle bound cpp functions callbacks
|
/// Handle bound cpp functions callbacks
|
||||||
|
|
|
@ -461,6 +461,20 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
|
||||||
|
|
||||||
m_loadingStyle = true;
|
m_loadingStyle = true;
|
||||||
try {
|
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);
|
onStyleApply(styleNode->tag(), styleNode);
|
||||||
callLuaField("onStyleApply", styleNode->tag(), styleNode);
|
callLuaField("onStyleApply", styleNode->tag(), styleNode);
|
||||||
|
|
||||||
|
@ -471,7 +485,6 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
|
||||||
focus();
|
focus();
|
||||||
}
|
}
|
||||||
m_firstOnStyle = false;
|
m_firstOnStyle = false;
|
||||||
|
|
||||||
} catch(Exception& e) {
|
} catch(Exception& e) {
|
||||||
logError("Failed to apply style to widget '", m_id, "' style: ", e.what());
|
logError("Failed to apply style to widget '", m_id, "' style: ", e.what());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue