Jump to content




tables with limited length and types


  • You cannot reply to this topic
1 reply to this topic

#1 Kouksi44

  • Members
  • 89 posts
  • LocationMunich, Germany

Posted 27 June 2015 - 10:12 PM

TypeTable


Well I was bored so I tried to make tables that only accept values of a certain type and have a limited size .

This is basically what I was able to produce :

Spoiler

The relevant functions are
typedTable( sType, nSize) 
addType(tbl,sType) 
deleteTable(pTbl) 
.

typeTable() simply returns a table that only allows values of the type given as the parameter ( the type can be a string or a table of strings ) and the specified size.

You can add new types through addType() and delete the whole table with deleteTable()


Pastebin:

 http://pastebin.com/42zgHJHh 

It´s no masterpiece and it didn´t take too long to code I was simply bored :D

Maybe it´s useful for someone :)

Kouksi44



#2 Lion4ever

  • Members
  • 91 posts

Posted 29 June 2015 - 06:28 PM

Nice :)

One useful programming trick for the future:
If you put the allowed type names in the table "validTypes" as a key and not as a value, you would not need a "contains" method.
local validTypes={ ["nil"]=true, boolean=true, string=true, ["function"]=true, thread=true, table=true }
if  sType and validTypes[sType] and type(nSize) =="number" then
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users