luaScript object is a way to call LUA script from inside QML script. Backward call (from lua to qml) is not possible. So QML should use functions’ calls to get fresh data from script always.
Object has next methods (functions):
- luaScript.callI – returns Integer;
- luasScript.callS – returns String;
- luaScript.callV – returns nothing (Void);
- luaScript.callSL – returns Strings List;
All those methods accept LUA’s function name as 1st parameter. 2nd parameter is optional and can be: integer, string, integer list (array), string list(array).
Sample:
Button {
id: brun
x: 6
y: 454
anchors.left: parent.left
anchors.leftMargin: 6
anchors.top: textBG.bottom
anchors.topMargin: 172
onClicked: luaScript.callV("run_clicked",edit.text)
skin: "./run.png"
}
This sample declares some button when it’s clicked it calls lua function “run_clicked” and passes text from “text edit box” to it. Lua file should have next:
function run_clicked(what)
local f,err = loadstring(what)
if f == nil then
showMsg(string.format("Error: %s",err))
else
local s,m = pcall(f)
if not s then
showMsg(string.format("Error: %s",m))
end
end
end
This version is not final but is minimal to solve tasks like programming I/O COM port terminal completelly using scripts.
1 Comment