←  General

ComputerCraft | Programmable Computers for Minecraft

»

Post code tricks here!

lieudusty's Photo lieudusty 02 Apr 2013

My lua trick
os.shutdown()
Quote

SuicidalSTDz's Photo SuicidalSTDz 02 Apr 2013

View PostSpongy141, on 02 April 2013 - 09:36 AM, said:

My favorite Lua trick is this
local var = read()
print(var)
yep, that is my favorite trick, got a problem?
Yeah, I do ^_^
print(read())
I just simplified your trick, now have a cookie :P
Quote

Imgoodisher's Photo Imgoodisher 03 Apr 2013

With this bit of code:
local tbl = setmetatable({}, {
__index = function(self, index)
  if not rawget(self, index) then
   rawset(self, index, {})
  else
   return rawget(self, index)
  end
end
})
you can have a 2-dimensional table without worrying about setting (for example) tbl[1] before setting tbl[1][5]. You could probably also put the code inside itself to make 3D tables... metatableception?
Quote

theoriginalbit's Photo theoriginalbit 03 Apr 2013

View PostPonyKuu, on 27 March 2013 - 08:23 PM, said:

TheOriginalBit, I have a question about your assert.
See my even newer one! :D
Quote

PixelToast's Photo PixelToast 03 Apr 2013

View PostImgoodisher, on 03 April 2013 - 01:22 PM, said:

also put the code inside itself to make 3D tables... metatableception?
you forgot to return an empty table after the rawset
anyway heres your metatableception:

rawset(self,index,setmetatable({},getmetatable(self))

i used a bit of that here
Quote