Skip to content

Instantly share code, notes, and snippets.

@jasonknight
Last active May 14, 2017 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonknight/ee129c0932bcbde22e4015d25e77eb13 to your computer and use it in GitHub Desktop.
Save jasonknight/ee129c0932bcbde22e4015d25e77eb13 to your computer and use it in GitHub Desktop.
Lua Object as a Function- https://repl.it/Hx2o/8
-- Lua object implemented with just functions.
function make(a,b)
return function(msg)
if msg == "a" then return a end
if msg == "b" then return b end
if msg == "mul" then
return function()
return a * b
end
end
if msg == "tostring" then
return function (str)
return string.format(str,a,b)
end
end
end
end
x = make(5,6)
y = make(42,3.14)
print(x("a"))
print(x("b"))
print(y("a"))
print(x("mul")())
print(y("tostring")("<%d,%d>"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment