Code: Select all
function hi()l={"h";"i";}io.write(l[1]..""..l[2]);io.write", world";end;hi()
Code: Select all
function hi()l={"h";"i";}io.write(l[1]..""..l[2]);io.write", world";end;hi()
Code: Select all
L
L Ö
Ö V
L Ö V E
Ö B E
V E
E Y
Code: Select all
debug.setmetatable(0, {__mul=function(j, f)if type(j)=="function"then j,f=f,j end for i=1,j do f(i,j)end return j end})
range = 1, 5
* function (i)
print("Hi",i)
end
* print
what does this do?szensk wrote:Something like this:Code: Select all
debug.setmetatable(0, {__mul=function(j, f)if type(j)=="function"then j,f=f,j end for i=1,j do f(i,j)end return j end}) range = 1, 5 * function (i) print("Hi",i) end
Code: Select all
L
L Ö
Ö V
L Ö V E
Ö B E
V E
E Y
Code: Select all
Hi 1
Hi 2
Hi 3
Hi 4
Hi 5
Code: Select all
-- set metatable for the number type
debug.setmetatable(0, { __mul = function(number, func) --override multiply operator to accept a function * number
if type(number) == "function" then
number, func = func, number -- arguments were in backward order
end
for i=1, number do
func(i, number) -- pass in current index and maximum index
end
return number
end})
__unused = print * 5
Code: Select all
function extend(entity, component)
for k, v in pairs(component)
if k != '_init' and entity[k] == nil then entity[k] = v end
end
if component._init then component._init(entity) end
return entity
end
function entity(body)
local object = { extend=extend }
if body then
object:extend(body)
end
return object
end
local example_component = {
x = 0, y = 0, w = 0, h = 0
_init = function(self)
print("do stuff here")
end,
}
local Player = entity():extent(example_component)
The non-equality test...fixed.Inny wrote: -snip-Code: Select all
function extend(entity, component) --snip-- if k ~= '_init' then --.... --snip-- end
I always wondered why lua used a tilde instead of a exclamation mark for the non equality test.Roland_Yonaba wrote:The non-equality test...fixed.Inny wrote: -snip-Code: Select all
function extend(entity, component) --snip-- if k ~= '_init' then --.... --snip-- end
Code: Select all
L
L Ö
Ö V
L Ö V E
Ö B E
V E
E Y
Heh! I can't tell you how many times in javascript I end up writing stuff like $(function() end) and then take a moment to realize why it don't do.Roland_Yonaba wrote:The non-equality test...fixed.Inny wrote: -snip-Code: Select all
function extend(entity, component) --snip-- if k ~= '_init' then --.... --snip-- end
Well, I can share a similar experience...Lots of time, when writing VBA macros (in MsExcel), I declare variables with "local". After struggling with the built-in debugger, I realize that it should be "dim" instead...Inny wrote:Heh! I can't tell you how many times in javascript I end up writing stuff like $(function() end) and then take a moment to realize why it don't do.
Users browsing this forum: Semrush [Bot] and 1 guest