Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Weird Lua OOP Lib
-- -- Go to the bottom for a sample -- local class; do local function copyTable(tbl) if type(tbl) ~= "table" then return tbl end local newTable = {} for i, v in pairs(tbl) do newTable[i] = copyTable(v) end return newTable end local classMt = {} function classMt:__newindex(key, value) self.vals[key] = value end function classMt:__index(key) error("Trying to index a class") end function classMt:__call(...) local instance = setmetatable(copyTable(self.props), {__index = self.vals}) self.vals[self.name](instance, ...) return instance end function classMt:__tostring() return ('<class "%s">'):format(self.name) end local function createClass(name, vals) local props = vals[1] or {} vals[1] = nil return setmetatable({name = name, vals = vals, props = props}, classMt) end class = function(name) return function(v) _ENV[name] = createClass(name, v) end end end -- -- Sample -- class("Vector2") { { x = 0; y = 0; }; } function Vector2:Vector2(x, y) self.x, self.y = x, y end local PlayerPosition = Vector2(30, 30) print(PlayerPosition.x)
run
|
edit
|
history
|
help
0
dd
hij
855
Non-Lua core for new scripting languages (Beta)
PAID HACK PuBG
Conta valores acima da média - LUA
Eliminatoria minigame
sh
Properties in Lua
Security keygen