[Date Prev][Date Next][Thread Prev][Thread Next]
- 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 <email@example.com>, Rob
Kendrick <firstname.lastname@example.org> wrote:
> On Tue, 15 Jul 2008 11:19:10 +0200 (MESZ) Michael Gerbracht
> <email@example.com> 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...)
> 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.
...using RiscLua 4.14, built from Lua 5.1.3