[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Indirect call to function and passing arguments
- From: Michael Gerbracht <smartmails@...>
- Date: Tue, 15 Jul 2008 12:26:28 +0200 (MESZ)
In article <20080715102944.76035463@trite.i.flarn.net.i.flarn.net>, Rob
Kendrick <lua-l@nun.org.uk> wrote:
> On Tue, 15 Jul 2008 11:19:10 +0200 (MESZ) Michael Gerbracht
> <smartmails@arcor.de> wrote:
> > function call(f,n) x = 5 y = loadstring("return "..f) z = y() print(z)
> > end
> >
> > call("add(n)",12)
> I'm going to assume your use of globals is intentional, rather than lack
> of style :) but try this;
Yes, in the real code I make use of local variables (which does not
exclude that the style is still lacking...)
> [code]
> There are perhaps more elegant solutions to this: it assumes the
> function is in the globals table.
Ok, thanks, this works for me.
> Perhaps put your callable functions in their own table and look them up
> in that?
I think about that but anyway the function will be _G or not?
> (I'm assuming you're receiving the "add" string from the user, and thus
> can't just do 'add(12)').
Yes, even the function itself may be defined by the user.
Thanks,
Michael
--
...using RiscLua 4.14, built from Lua 5.1.3