Moderators: They make you lose count(Longest thread still alive!)

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
Code:
local t={}
setmetatable(t,{
__index = function(t,k) return {1,2,4} end
})

print(table.concat(t.luaBeingLua,""))
Guess what this does and how it works. (assuming I didn't screw the code up which is possible as I did not test it)

edit: I should have just done this
Code:
local t={}
setmetatable(t,{
__index = function(t,k) 
   return 1,2,4
end
})

io.write(t.luaBeingLua)
io.write("\n")
I worked too much with languages that can only return 1 thing >_<
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
132 also, about what it is supposed to do:
When you want to find a value in a table that is not set lua looks for the __index value of the metatable of that table. If its a function it executes it

Thus when I asked it to find the value of luaBeingLua in table "t" it should run the index value and thus return 1,2,4.
io.write() takes an infinite amount of arguments and print them. However unlike print() it doesn't put a newline character at the end of it and what it needs to do when the arguments are split are very strictly documented, unlike print which depending on the interpreter will either print a tab in between the values, a space or perhaps even nothing (which I don't think I encountered yet myself but I wouldn't be surprised if there is an interpreter out there that does that).

However I personally never found this a problem due to me either only using print to debug things (not in all projects but like the thing I am working on right now that is defiantly the case), I know how the interpreter that it is going to run on handles it or because the difference is just very tiny