`showcase of Lua tables

disable escapekey
set window on
set display mode 800, 600, 32

`initialize lua interface
LUA MAKE
`load lua file
LUA LOAD FILE "tables.lua"

`fun with LUA tables
`this is messy on purpose!
print "my greatgrandpa would be " + str$(LUA INT("greatgrandpa.age")) + " years old, if he wasn't dead..."
print "my grandpa is " + str$(LUA INT("grandpa.age")-LUA INT("grandma.age")) + " years older than my grandma."
print "my grandma is the daughter of my greatgrandpa, she was born when he was " + str$(LUA INT("greatgrandpa.age")-LUA INT("grandma.age")) + " years old."
print "my dad is the son of my grandpas. he is " + str$(max(LUA INT("grandpa.age"),LUA INT("grandma.age"))-LUA INT("pa.age")) + " years younger than my older grandparent."
print "I was born when my dad was " + str$(LUA INT("pa.age")-LUA INT("pa.child.age")) + " years old."
print ""
print "so, how many years did I survive already in this world?"
check_for_error()
input "", guess_my_age$
guess_my_age = val(guess_my_age$)
if guess_my_age = LUA INT("greatgrandpa.child.child.child.age")   `is equal to "me.age"! funny isnt it?
   print " CONGRATULATIONS! You are RIGHT!!! "
else
   print "nope, sorry, wrong guess..."
endif
print ""
wait 500

print "hit any key to exit"

`test functions and memory leaks -- they work, no leaks.
LUA NEW TABLE "test"
LUA NEW TABLE "test.nest"
LUA NEW TABLE "test.nest.deep"
while (scancode()=0)
   i = rnd(1000)
   LUA SET INT "test.i", i
   if i <> LUA INT("test.i") then print "table int error!"
   f# = rnd(100) / 100.0
   LUA SET FLOAT "test.f", f#
   if f# <> LUA FLOAT("test.f") then print "table float error!"
   s$ = str$(rnd(100000))
   LUA SET STRING "test.s", s$
   if s$ <> LUA STRING$("test.s") then print "table string error!"
   i = rnd(1000)
   LUA SET INT "test.nest.i", i
   if i <> LUA INT("test.nest.i") then print "table nest int error!"
   f# = rnd(100) / 100.0
   LUA SET FLOAT "test.nest.f", f#
   if f# <> LUA FLOAT("test.nest.f") then print "table nest float error!"
   s$ = str$(rnd(100000))
   LUA SET STRING "test.nest.s", s$
   if s$ <> LUA STRING$("test.nest.s") then print "table nest string error!"
   i = rnd(1000)
   LUA SET INT "test.nest.deep.i", i
   if i <> LUA INT("test.nest.deep.i") then print "table nest deep int error!"
   f# = rnd(100) / 100.0
   LUA SET FLOAT "test.nest.deep.f", f#
   if f# <> LUA FLOAT("test.nest.deep.f") then print "table nest deep float error!"
   s$ = str$(rnd(100000))
   LUA SET STRING "test.nest.deep.s", s$
   if s$ <> LUA STRING$("test.nest.deep.s") then print "table nest deep string error!"
   check_for_error()
endwhile


end


function max(a,b)    `returns the max of two numbers
   result = a
   if a < b then result = b
endfunction result

function check_for_error()
   `Display message and terminate program if a LUA error has occurred.
   if LUA ERROR()
      print LUA ERROR MSG$()
      wait key
      end
   endif
endfunction