Lua for Blitz

Blitz3D Forums/Blitz3D Userlibs/Lua for Blitz

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Ouch, haven't looked in the code since posting. The bad thing is i don't know how we could call a blitzfunction from within a lua script. I had a look in the BMax forum, where there are some more usage examples. You should get yourself the header- and sourcefiles from www.lua.org and have a look in the programmers handbook available online. Sorry, but i don't know much more about this right now.
Include "BlitzLua.bb"

; creates a lua state, sort of runtime environment
; every lua function must provided the actual lua state
l = lua_open()
; includes the base library in lua
luaopen_base(l)
; includes the io library
luaopen_io(l)
; includes the string library
luaopen_string(l)
; includes the math library
luaopen_math(l)
; this calls a script
LUA_callScript(l, "hello.lua")
; try to find the expression <foo> in the script
; global might be a Function or variable
LUA_getGlobal(l, "foo")
; this will actually perform the script
; we call the function foo with <0>  zero parameters and
; want get <1> one result							
lua_call( l, 0, 1 )
; print the result as string
Print lua_tostring(l, -1)
; and pops it from the lua stack
LUA_pop( l, 1 )
; now we have finished and close the state
lua_close(l)

WaitKey()
End

-----------------------------------------
www.moonworx.de