Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Properties in Lua
function enablePropertySupport(x) x.mt = {} setmetatable(x,x.mt) function x.mt.__index(t, k) if string.sub(k,1,4) == 'get_' then return nil end local getter = t['get_'..k] if getter ~= nil then return getter(t) else return error('There is no read access for a property called '..k) end end function x.mt.__newindex(t, k, v) if string.sub(k,1,4) == 'set_' then return nil end local setter = t['set_'..k] if setter ~= nil then setter(t, v) else return error('There is no write access for a property called '..k) end end end x = {} x.z = 7 function x:get_value() return self.z end function x:set_value(v) self.z = 2 * v end enablePropertySupport(x) x.z=8 print(x.value) x.value = 21 print(x.value)
run
|
edit
|
history
|
help
0
test123
multiline string
roulette
Lua Timer
Show current system clock
Creating habits v2, Lua (WIP)
Map generator
5+5 == 10
10 Line challenge
Conta valores acima da média - LUA