Tlist and integers
BlitzMax Forums/BlitzMax Beginners Area/Tlist and integers
| ||
I've always been under the impression that TLists only works with Objects. If I try to compile this code mylist:TList=CreateList() For i=0 To 5 ListAddLast MyList,i Next For s=EachIn MyList Print s Next The compiler will complain that it expect an object for the eachin index. So is it correct for me to make a statement that TList works with objects only. Skidracer (in this post seems to suggest it does work with int). How would you use it w integers correctly? |
| ||
I think what he may be refering to there is that in non-strict mode, the compiler will let you assign an integer to a list, but it's really a null object:' Strict Local myList:TList = CreateList() ' Local myList:Int = CreateList() Local obj:Object = "Hey, I'm a string!" Local i:Int For i = 0 To 5 ListAddLast myList, i ListAddLast myList, obj Next Local c = CountList( myList ) Print "Count = " + c Local o:Object[] = ListToArray( myList ) For i = 0 To c - 1 If o[i] = Null Then Print i + " = null" Else Print i + " = " + o[i].ToString() EndIf NextThis code runs fine, but shows that "i" is actually assigned as a null. If you un-comment Strict, you'll need to comment out "ListAddLast myList, i". Also interesting is that with Strict commented out, you can declare myList as an Int rather than as a TList (swap the commenting in the declarations) and it will still run. However, then element 1 of the converted array shows up as a handle(?!), while the rest appear as strings or nulls. I'd think that both of these issues are unintentional and it wouldn't surprise me if they were changed(/fixed)in a future update. |