Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline function tables in lua

Tags:

lua

I cannot seem to find any other online help about creating a table which contains functions which are multiline. For example, here is a snippit of code from the lua wiki.

action = {
  [1] = function (x) print(1) end,
  [2] = function (x) z = 5 end,
  ["nop"] = function (x) print(math.random()) end,
  ["my name"] = function (x) print("fred") end,
}

I want to do something like this:

action = {
[1] = function blah()
more code here
end

[2] = function blahblah()
more code here
end

}

So how can I do so?

like image 659
haws1290 Avatar asked Sep 10 '26 03:09

haws1290


1 Answers

action = {
  [1] = function (x)
    print(1)
  end,

  [2] = function (x)
    z = 5
  end,

  ["nop"] = function (x)
    print(math.random())
  end,

  ["my name"] = function (x)
    print("fred")
  end,
}

You are free to do that.

like image 65
dlask Avatar answered Sep 13 '26 05:09

dlask



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!