Monday, April 16, 2012

[FA] sending function name in table value.

Hi,
well as the topic surgests, i want to send a function name in a table value, in one lua lua file, then i want to call that function in another lua file..
how can i do this?|||Can you be more specific? Why do you need to do this? Why not just define the function in the other file, import, and call it?
Remember that functions are just variables like any other, and can be referred to by their key name in whatever table they exist in (including _G). If this is a class member function, and you need to get the name via string from an external source, you can call it from within a class function via self[functionName](...). Same if it's in a global table in the calling environment. If the function is defined within the global environment (e.g. defined directly within an imported script file), you should be able to call it in that environment via _G[functionName](...) or getfenv()[functionName](...) - I'm pretty sure that [functionName](...) does not work, but I've never tried it.
However, there is probably a better way to architect whatever you're doing, which is why I asked for more specifics.|||Mithy|||Hi,
Sorry for the delay in answering, i didnt get emails to say new posts in this thread :/
anyway.. i did what i needed to do a different way...
i still dont fully understand why it didnt work the first time round.. i tried various things.. which i have forgot now..
anyway suffice to say.. what i was working on is now working :)
Thx for the replies :)

No comments:

Post a Comment