'How to assign string to a function in lua
I am writing a calculator based on the script I have in Python and for the arithmatic operators I used:
operations={'ADD':add,'PLUS':add,'SUM':add,'ADDITION':add,
'SUB':sub,'SUBTRACT':sub, 'MINUS':sub,
'DIFFERENCE':sub,'LCM':lcm,'HCF':hcf,'PRODUCT':mul,
'MULTIPLY':mul,'MULTIPLICATION':mul,
'DIVISION':div,'MOD':mod,'REMAINDER':mod,'MODULAS':mod}
This was the python one but the same idea does not work for Lua.
In the example the format goes:
{'UserInput':Function}
Any help would be appreciated.
I tried replacing : with -> and = but none of them worked.
Solution 1:[1]
The equivalent of this python code:
t = {"foo": "bar", "one": "two"}
t["foo"]
in lua is:
t = {["foo"] = "bar", ["one"] = "two"}
t["foo"]
or:
t = {["foo"] = "bar", ["one"] = "two"}
t.foo
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
