LuaMotif and Callbacks
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: LuaMotif and Callbacks
- From: Marc Balmer <marc@...>
- Date: 2012年4月07日 09:37:46 +0200
It is very easy to define a callback when creating a widget hierarchy in
LuaMotif:
myform = Form {
RowColum {
Label {
labelString = 'Hello, World!'
},
PushButton {
labelString = 'pushme',
activateCallback = function ()
print('A button has been pushed')
end
}
}
}
But what when you want to pass parameters to that function? I resorted
to some kind of convention (to avoid the word 'hack'):
data = {42, 'Mr. Wong', 'foo', function () print('hello') end }
myform = Form {
RowColum {
Label {
labelString = 'Hello, World!'
},
PushButton {
labelString = 'pushme',
activateCallback = Callback {
function (data)
print('hi there ' .. data[2])
end,
data
}
}
}
}
"Callback" is a pseudo widget that by convention takes a function in [1]
and data to be passed to the function in [2].