lua-users home
lua-l archive

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


On Fri, Jun 24, 2011 at 22:20 PM,  Patrick Donnelly
<batrick@batbytes.com> wrote:
> On Fri, Jun 24, 2011 at 6:53 PM, Matthew Wild <mwild1@gmail.com> wrote:
>> On 24 June 2011 21:53, Gavin Wraith <gavin@wra1th.plus.com> wrote:
>>> In message <BANLkTi=ndaPq1pPopn=Jjh7KwVmbo2PEUA@mail.gmail.com> you wrote:
>>>
>>>> On 24 June 2011 21:26, Patrick Donnelly <batrick@batbytes.com> wrote:
>>>> > On Fri, Jun 24, 2011 at 3:57 PM, Kev Lugli <kevlugli@gmail.com> wrote:
>>>> >> Hi, I'm trying to do something like this, but I've got no success yet.
>>>> >>
>>>>
>>>> and you don't need _G:
>>>>
>>>> a = 'func'
>>>> var = {}
>>>>
>>>> var[a] = function (a)
>>>>  print(a)
>>>> end
>>>
>>> This is simply
>>>
>>>  var = { func = print }
>>>
>>> if you overlook the variadic nature of print. I am asking myself if
>>> somewhere along the way someone had overlooked the fact that
>>> the variable 'a' is a constant (i.e. bound to 'func') on the
>>> lefthand side of the assignment but a dummy variable (i.e. bound by
>>> 'function') on the righthand side. Or have I misunderstood the point
>>> of the exercise?
>>>
>>
>> Maybe, but perhaps I did - I just assumed the function would do
>> something more useful than (unsuccessfully) wrap print() :)
>
> He was having trouble with the syntax/semantics. I was trying not to
> distract from the problem by optimizing a frivolous example : /.
>
> --
> - Patrick Donnelly

Thanks! You've been very helpful. Now, I'd like to know how to do the
same, but with a colon operator. The thing is that I'm doing a working
days calendar's script with lua and IUP, and I want to automate the
creation of days. The piece of code is this:


-------------------------------Begin Of Code---------------------------------
function addnewday(name)
	_G['chk'..name] = iup.toggle {title = name}
	_G['txtFrom'..name] = iup.text {spin = 'yes', active = 'no', size =
'40', spinmax = '24', spinmin = '1', spinvalue = '12' }
	_G['txtTo'..name] = iup.text {spin = 'yes', active = 'no', size =
'40', spinmax = '24', spinmin = '1', spinvalue = '12' }
	_G['frm'..name] = iup.frame {
								iup.vbox {
										_G['chk'..name],
										iup.hbox{iup.label {title = 'From'}, _G['txtFrom'..name]},
										iup.hbox{iup.label {title = To'}, _G['txtTo'..name]}
										}
								}
	table.insert(listOfDays, _G['frm'..name])
	_G['chk'..name..':action']= function (a)
		print ('a')
		_G['txtFrom'..name..'.active'] = 'yes'
		_G['txtTo'..name..'.active'] = 'yes'
	end
end

addnewday('Monday')
addnewday('Tuesday')
addnewday('Wednesday')
addnewday('Thursday')
addnewday('Friday')
addnewday('Saturday')
addnewday('Sunday')

-------------------------------End Of Code---------------------------------

The function " 'chk'..name..':action' " is never called whenever I
check any of the toggle controls, so I think it' s a problem with the
name of it.