Jump to content




Generic Table... kind of


  • You cannot reply to this topic
2 replies to this topic

#1 Kouksi44

  • Members
  • 89 posts
  • LocationMunich, Germany

Posted 19 January 2017 - 11:16 PM

This is probably pretty useless, but hey maybe someone can make something out of it...

This neat little tool allows you to define Lists that hold values of a certain type only. Doesn't sound like much but atleast it looks kind of pretty...

local myList = List : number {
  34;
  35;
  36;
}

As you can see you declare a List by writing:
List : <YourSuperSpecialType> {}

You can pass some initial values to the List by passing a table after the List type.

Another super nice feature is, that you can create your own "types" for your Lists. Lets say you want a List of e.g. Vectors.
That can be done by declaring a table with a __type field. Now if that field is defined to be
__type = "Vector"
these tables will be treated as if they were of type "Vector".
Comes in handy if you're writing some oop code and want to have List of your objects.

Install:
pastebin get 9mJL4rgH

Let me know if this usefull in any way or not ^^

#2 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 21 January 2017 - 01:02 AM

Actually, this is really awesome! I like the syntax a lot, and it feels much better to work with more restricted tables than this "I take everything I can"-type of "table" we have in Lua. I'm trying to get into function programming and this might come in handy when doing some "functional lua" ;)

#3 Kouksi44

  • Members
  • 89 posts
  • LocationMunich, Germany

Posted 23 January 2017 - 12:30 AM

Somehow I was able to forget to explain pretty much anything except for the most basic features... great.
I added a few more helper functions, most of them are simply their table.XXX() equivalent wrapped in another function to make them work with Lists.

Things you can now use:
Spoiler

Additionally, if you just want to add a value to the end of the list , you can now use this syntax:
<yourList> = <yourList> + 77


Updated the pastebin link in the main post !

Edit: Just in case anyone was wondering, yes you can make Lists containing Lists. List objects do have a __type field defining them as List objects.

Edited by Kouksi44, 23 January 2017 - 12:34 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users