lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Marc Balmer <marc@msys.ch> writes:
> It is very easy to define a callback when creating a widget hierarchy in
> LuaMotif:
...
> 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 {
...
> 			activateCallback = Callback {
> 				function (data)
> 					print('hi there ' .. data[2])
> 				end,
> 				data

Why can't you just make the callback a closure, and reference "data"
directly from it (without making it a parameter)?

e.g.:

> data = {42, 'Mr. Wong', 'foo', function () print('hello') end }
>
> myform = Form {
...
> 			activateCallback = function ()
> 					print('hi there ' .. data[2])
> 				end

?

-miles

-- 
"Yorton, Wressle, and Gospel Oak, the richness of your heritage is ended.
We shall not stop at you again; for Dr Beeching stops at nothing."