Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,4 @@
local object = { name = "foo", func = function (self) print(self.name) end }
object:func() -- with : sugar
object.func(object) -- without : sugar

View file

@ -0,0 +1,9 @@
local methods = { }
function methods:func () -- if a function is declared using :, it is given an implicit 'self' parameter
print(self.name)
end
local object = setmetatable({ name = "foo" }, { __index = methods })
object:func() -- with : sugar
methods.func(object) -- without : sugar

View file

@ -0,0 +1,16 @@
local count = 0
local box = { }
local boxmt = { __index = box }
function box:tellSecret ()
return self.secret
end
local M = { }
function M.new ()
count = count + 1
return setmetatable({ secret = count, contents = count % 2 == 0 and "rabbit" or "rock" }, boxmt)
end
function M.count ()
return count
end
return M

View file

@ -0,0 +1,6 @@
local box = require 'box'
local b = box.new()
print(b:tellSecret())
print(box.count())