Lua Scripting and Blizt3d

Community Forums/General Help/Lua Scripting and Blizt3d

YellBellzDotCom(Posted 2011) [#1]
Has anyone seen any Lua Scripting for Blitz3d for dummies laying around? I have been working on a game in b3d and would like to incorporate a scripting engine and from what I have seen LUA looks to be top of the line. Problem is I have never used it or know where to start.

Any pointers would be greatly appreciated!


Yasha(Posted 2011) [#2]
You can't use any generic pre-packaged Lua libraries by themselves, because Blitz3D has no native support for function pointers (this applies to almost all scripting languages not actually implemented in Blitz3D). Without function pointers, there's no way to pass game engine functionality to a script, so you can't really use it for much more than numeric calculation. (Obviously any scripting engines implemented in B3D code can simply use integer function "handles" and a switch table, which is ugly and inefficient, but does the job.)

You can get Blitz3D function pointers by using the FastPointer library by MikhailV, but this is a hack, so be aware that it may break at any time, void your cow's warranty, blah blah. FastPointer is also not guaranteed to work correctly with the B3D debugger (you can't step through functions reached via CallFunction).

Apart from that, it should be as simple as plugging it in and getting started. You have to make sure that the Lua interface functions are all __stdcall (which is easy to fix since Lua is open source - you should be able to just add "__stdcall" to the definition of LUA_API in luaconf.h) and then you ought to be able to use it pretty much as you would in C.

In fact I'm tempted to give this a try myself right now. Check back in a few minutes... but am not going to because I need to learn self-control.


However, if you've never used Lua, is it really the best choice?

Last edited 2011


YellBellzDotCom(Posted 2011) [#3]
Wow, that was quite a surprise. I really wasn't expecting that. I really appreciate the heads up there.

I seriously doubt including LUA would ultimately be worth it in the end. I will just concentrate on the game itself. It sounds like it would take me alot longer to learn the implementation of a scripting engine then it would take to actually get the game up and running.

I was just interested in adding scripting to the game for future modifications, or quick game editing instead of having to re-compile the entire game.

Thanks for the help!


Yasha(Posted 2011) [#4]
The lack of any really good scripting engines for Blitz3D is an ongoing annoyance, really. I've been meaning to rectify it just about forever, but never quite seem to get around to it.

The medium-level solutions I would recommend are:

-- GameScript, by John J. This provides a fast compiler and interpreter for a language somewhere in between Blitz3D and BlitzMax. Unfortunately, it seems to have some bugs, and the really odd part is that it's mainly designed for "asynchronous" scripting (i.e. GS scripts are essentially whole programs that run in a second pseudo thread alongside your program, rather than swappable functions that are called-and-return like every other scripting engine, ever).

-- TinyScheme, as linked in my sig. While Scheme seems to have fallen from popularity in the last couple of years, TinyScheme is the official scripting engine of the GIMP, so it comes with a good reputation and isn't buggy. Does require you to learn Scheme, which won't take long (for small tasks), because it's a very simple language, but may be something of a shock to the system.

There are a few other projects floating around, but I wouldn't recommend them. Tiny C Compiler offers unparalleled speed due to emitting true machine code, but has obscure bugs and no error messages; BriskVM is apparently reliable, but it costs money and is closed source, and really isn't much of a step up language-wise. And I've started a couple of interpreters and never got around to finishing them...

At the very least, there ought to be both Lua and JavaScript engines available, and something like Tcl (in the form of JimTcl or Picol) would also probably be very appropriate for Blitz3D. I really need to get around to making these happen.


YellBellzDotCom(Posted 2011) [#5]
Blitz3d and JavaScript? Now that would be entertaining.

I really appreciate the information and help. I will poke around a little once I get to a certain point. All I was really looking for was something I could use to load maps and modify some game game settings. In reality I could just use some config files for this, but well see how it comes along.

Thanks for the help!


Dodo(Posted 2011) [#6]
I came across this when doing a random scripting search, it's expensive though!

Last edited 2011


Noobody(Posted 2011) [#7]
Hi,

About two years ago I wrote a working Lua wrapper for B3D that you might be interested in.

It works by doing a bit of ASM magic to get the adress of one specific blitz function, which is then exposed to Lua. All function calls from Lua to blitz are handled through this function.
Although it is a bit more inconvenient than being able to expose B3D functions directly, it still works quite well.

The wrapper is free, comes with a few examples and can be downloaded here.