lua-users home
lua-l archive

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

Recursive design.

msg_union = {
  ["0"] = "alt1",
  ["1"] = "alt2",

function alt1 (body)
function alt2 (body)

ielen = _G[msg_union[tostring (selector)]] (buffer(offset), pinfo, tree)

Maybe there's a better way?  It looks like it's going to be slow.

The msg_union has to be defined before it can be used by the (sub)msgs.  But it needs access to the (sub)msgs.

On Mon, Oct 6, 2014 at 2:17 PM, Rob Kendrick <> wrote:
On Mon, Oct 06, 2014 at 02:15:36PM +0200, Charles Smith wrote:
> Okay, I got it to work:
> v = "m1"
> function m1 ()
>     print ("hello world")
> end
> _G[v]()

I'm trying, and failing, to see a situation where this is the most
elegant solution.

Can't you just define the function first?  Calling functions by name
rather than value is fraught with horror.