axe.luascript help

BlitzMax Forums/BlitzMax Programming/axe.luascript help

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.

I'm interested in Lua :-). Although I used axe.lua. I don't know what axe.luascript is?

The tutorial over at GameDev helped me understand how to use Lua in BlitzMax: http://www.gamedev.net/reference/programming/features/lua/

You can skip the first pages since it's about implementing it in C++ but the rest is almost the same as with BlitzMax.

Here's a small example:

test.bmx
SuperStrict
Import axe.lua

Local LuaState:Byte Ptr = luaL_newstate()
luaL_openlibs(LuaState)

lua_pushstring(LuaState, "BMXString")
lua_setglobal (LuaState, "luaglobal")

lua_register(LuaState, "BMXName", BMXName)
luaL_dofile(luaState, "test1.lua");
lua_close(LuaState)

End

Function BMXName:Int (LuaState:Byte Ptr)
	' handling of parameters passed from Lua (if required)
	' actual function body
	' passing results back to Lua (if required)
	luaL_dostring(LuaState, "print('Ahum!')")
	Return 0 ' number of values returned to Lua
End Function


test.lua
print("Test!");
print(luaglobal);

-- Simple lua script
-- comments indicated with a '--'
a = 5;
b = 10;
c = a + b;
print ("5+10=" .. c);

BMXName();



Very simple example but it does show how you can call your BlitzMax functions in a Lua script.

As for methods, I'm now sure. Native Lua doesn't support it if I'm correct. I must say I haven't done a lot with Lua yet but the way I figured is that you need to create Functions that can access the required object.