Jump to content




Post code tricks here!


44 replies to this topic

#41 lieudusty

  • Members
  • 419 posts

Posted 02 April 2013 - 03:13 PM

My lua trick
os.shutdown()


#42 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 02 April 2013 - 03:15 PM

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

#43 Imgoodisher

  • Members
  • 67 posts
  • LocationYes

Posted 03 April 2013 - 01:22 PM

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?

#44 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 03 April 2013 - 03:17 PM

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

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

#45 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 03 April 2013 - 04:06 PM

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users