ipairs in LUA

BlitzMax Forums/BlitzMax Programming/ipairs in LUA

slenkar(Posted 2009) [#1]
function Update(argh)
local trev = {}
trev[1]=x
trev[2]=y
trev.x=111
trev.y=222

for i,v in ipairs(trev)
do
print (i.."-"..v)
end

end

When i run this script it says : attempt to call global ipairs 'a nil value'


Htbaa(Posted 2009) [#2]
Did you load all libraries? By default no libraries are loaded so that might be the reason you get a message that ipairs doesn't exists.


slenkar(Posted 2009) [#3]
oh yeah thanks


slenkar(Posted 2009) [#4]
i put lual_openlibs in the blitzmax source,
does there have to be something in the LUA source to open libraries?


Htbaa(Posted 2009) [#5]
Try using pairs() instead of ipairs()

Also, I suggest you use the pil as a reference/tutorial. It's a great Lua book.


slenkar(Posted 2009) [#6]
I got it to work now, thanks for all the help


slenkar(Posted 2009) [#7]
does anyone know how to know what type of object is given by the pairs functions?

e.g. string, integer, table

I checked the manual but could only find functions like that in the host program.


JaviCervera(Posted 2009) [#8]
Can't you obtain the type with print(type(ipairs(trev))) ?


slenkar(Posted 2009) [#9]
oh yeah 'type' is the command thanks