Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

testing for variable types  [SOLVED]

All about the StoneScript

testing for variable types

Postby HaggisMcHaggis » 26 Jul 2012, 06:36

Hi All,

I currently have a table that stores different variable types. Is there a way of testing what kind of variable is stored when looping through it? Eg In my table, I have 1 string, 1 number and another table. How would I go about doing this in LUA script?
HaggisMcHaggis
Fresh Boarder
Fresh Boarder
 
Posts: 15

Re: testing for variable types

Postby freezer » 28 Jul 2012, 11:53

you can test using a few lua functions...

http://www.lua.org/manual/5.1/manual.html/#pdf-tonumber

tonumber()
tostring()
type()


*** not tested
freezer
Gold Boarder
Gold Boarder
 
Posts: 214

Re: testing for variable types

Postby freezer » 29 Jul 2012, 22:25

freezer
Gold Boarder
Gold Boarder
 
Posts: 214

Re: testing for variable types  [SOLVED]

Postby Fraser » 30 Jul 2012, 17:21

LUA has "type" function, which returns a string containing the type of the passed var:

http://www.lua.org/pil/2.html

What you want to do is not possible in stonescript which is a subset of LUA. This may change in Shiva2.

You will have to use seperate tables for each type, or you will have to interleave types in a known order.
Fraser Ashworth,
https://www.cortex7.net
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1040
Location: Europe

Re: testing for variable types

Postby HaggisMcHaggis » 11 Aug 2012, 02:35

Thanks for that :) I've solved it using different tables.
HaggisMcHaggis
Fresh Boarder
Fresh Boarder
 
Posts: 15


Return to Game programming