eval.in

Paste #161

Lua — Lua 5.2.1, pasted 4 years ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
local GreeterMeta = {}
GreeterMeta.__index = GreeterMeta

function GreeterMeta:greet()
   print("Hello " .. self.name .. "!")
end

function Greeter(name)
  local self = {}
  setmetatable(self, GreeterMeta)
  self.name = name
  return self
end

greeter = Greeter("Charlie")
greeter:greet()

Program Output

Hello Charlie!

OK (0.004 sec real, 0.001 sec wall, 3 MB, 13 syscalls)

Fork