Patmaba (or Mabiz?)
I do not know C++ (and also refuse to learn it ;-) ), but I can tell you how to work with BlitzMax classes.
First, become familiar with the Lua API - I applied a number of modifications to what is built into BlitzMax, the actual version may be downloaded from my web site (http://www.Andreas-Rozek.de/BlitzMax/lua.mod.zip) Unpack the archive, replace the original module with my version and rebuild the modules - now you will have all you need.
Use of the API is quite straightforward - if you already know it from C, which I assume. Otherwise I would have to explain too much right now.
Apart from string handling (which you don't have to think about, if you
- use ANSI characters only
- never use Strings as some kind of "byte array" (with embedded zeros) under Lua
) the only special "trick" is how to transparently pass BlitzMax objects to and from Lua.
The important keyword is "Handles": create a "handle" for your BlitzMax object (which actually looks like an "int") and pass it as "lightuserdata" to Lua - on its way back, grab the "lightuserdata" from Lua's stack, and reconstruct the BlitzMax object from that handle. An example shall illustrate this:
passes an arbitrary object (represented by the ellipsis ...) to Lua.
reconstructs a BlitzMax object (in this example of type TEvent) from Lua userdata grabbed from the stack at position "StackIndex"
Registering a BlitzMax function is also straightforward:
Within that function, you have full access to all your BlitzMax objects. Just take care of the Lua stack and don't forget to return the number of values your function wants to return to Lua!
I do not know C++ (and also refuse to learn it ;-) ), but I can tell you how to work with BlitzMax classes.
First, become familiar with the Lua API - I applied a number of modifications to what is built into BlitzMax, the actual version may be downloaded from my web site (http://www.Andreas-Rozek.de/BlitzMax/lua.mod.zip) Unpack the archive, replace the original module with my version and rebuild the modules - now you will have all you need.
Use of the API is quite straightforward - if you already know it from C, which I assume. Otherwise I would have to explain too much right now.
Apart from string handling (which you don't have to think about, if you
- use ANSI characters only
- never use Strings as some kind of "byte array" (with embedded zeros) under Lua
) the only special "trick" is how to transparently pass BlitzMax objects to and from Lua.
The important keyword is "Handles": create a "handle" for your BlitzMax object (which actually looks like an "int") and pass it as "lightuserdata" to Lua - on its way back, grab the "lightuserdata" from Lua's stack, and reconstruct the BlitzMax object from that handle. An example shall illustrate this:
lua_pushlightuserdata(LuaState,Byte Ptr(HandleFromObject(...)))
passes an arbitrary object (represented by the ellipsis ...) to Lua.
TEvent(HandleToObject(int(lua_touserdata(LuaState,StackIndex))))
reconstructs a BlitzMax object (in this example of type TEvent) from Lua userdata grabbed from the stack at position "StackIndex"
Registering a BlitzMax function is also straightforward:
function BlitzMaxFunction:int (LuaState:Byte Ptr) ... return 0 ' well, actually this is a "procedure" end function lua_register(Lua_State, "LuaNameForTheFunction", BlitzMaxFunction)
Within that function, you have full access to all your BlitzMax objects. Just take care of the Lua stack and don't forget to return the number of values your function wants to return to Lua!