GLOBAL L TYPE long*
GLOBAL x,y,result TYPE double

SETENVIRON "LANG","C"

INCLUDE "lua.bac"

L = luaL_newstate()
luaL_openlibs(L)

'vars we'll pass to Lua
 x = 5
 y = 6
 
 'open up a lua file in the current directory
 luaL_dofile(L, "hello.lua")

'push a global onto the stack
 lua_getglobal(L, "f")
 lua_pushnumber(L, x)
 lua_pushnumber(L, y)

' 2 arguments, 1 result
IF lua_pcall(L, 2, 1, 0) ISNOT 0 THEN
    'if a problem arose, print the error from the top of stack (-1)
    tt$ = lua_tolstring(L, -1, 0)
    PRINT CONCAT$("error running function ", tt$)
END IF

'it succeeded, get value off the stack (1.746347)
result = lua_tonumber(L, -1)

'pop it
lua_pop(L, 1)

PRINT result

lua_close(L)