Page 1 of 1

lua bzfsAPI plugin

Posted: Wed Dec 31, 2008 12:26 am
by trepan
For those that don't track SVN commits, I've added a lua plugin to the SVN sources.

There are several advantages to using scripting languages (lua, javascript, python, etc...),
for plugins instead of using the raw C++ interface.

1. no need to compile (or have bzfsAPI dev sources)
2. usually much easier to dev / debug
3. an extra layer of OS independence (works anywhere)
4. with recent bzfs changes, can be easily embedded in world files, ex (in test.bzw):

Code: Select all


# block comments
  BZ.AttachMapObject('/*', '*/', function() end)
  BZ.AttachMapObject('-/*', '*/', function(name, data) return data end)

a multiline comment
thanks to lua

  size 10 10 10

  local lines = {}
  for x = -100, 100, 10 do
    for y = -100, 100, 10 do
      table.insert(lines, 'box')
      table.insert(lines, 'pos " .. x .. ' ' .. y .. ' ' .. 40)
      table.insert(lines, 'size 3 3 31)
      table.insert(lines, 'end')
  return lines
NOTE: what isn't show here is that you can also add dynamic scripts in the bzw
file (ex: Airspawn and the like are very easy to build into the world file).

Using a scripting language also has its disadvantages:

1. probably isn't as fast as raw C++
2. might not have all of the C++ interface features implemented
3. might not be able to link to external libraries easily
(although the lua plugin can link to external dlls, but they should
be compiled against the bzflag lua sources)

Lua has a particular advantage in that it might also be used for client-side scripting
(I've got a large portion of the work already done, having started with the work that
I did for the Spring RTS project). If / when I commit, the post for that will have
cooler screenshots than this post ;-)

Re: lua bzfsAPI plugin

Posted: Wed Dec 31, 2008 2:31 am
by optic delusion
This is the biggest thing to happen to bzw, since the invention of bzw.
Thanks for the super-simple example world, Trepan. That's exactly what we need. It's the first steps that are the hardest.

Re: lua bzfsAPI plugin

Posted: Wed Dec 31, 2008 6:00 am
by trepan
For more examples of what lua plugins will look like compared to C++ ones,
take a look in the following directory: ... e/plugins/

Those plugins are "luafied" versions of C++ plugins which already exist. Instead of having
to load each plugin individually via a command line, I've continued what I started with Spring
and set it up so that a directory is scanned for lua module files, and then the code is loaded.
They will require the completion of 'modules.lua' before being useable by the general public.

Note that the LuaWorld and LuaUser client-side modules would look much the same.

As for this being the biggest thing to happen to bzw, I disagree. I consider the addition of
meshes and custom texturing to be more important for the reason that they allow changes
that would otherwise not be possible client-side. BZFS plugins are great for making server
modifications, but they could also be done by editting bzfs to suit your needs (or by
applying a patch).

And to give credit where credit is due:
- JeffM made bzfs plugins possible
- JeffM added bzfs plugin based custom map objects

P.S. Custom bzw objects are a headache for external editors, keep that in mind ;-)

P.P.S. The lua bzfs plugin could easily be migrated into the bzfs exec, and that is something
that I've considered (both for ease of use, and for execution speed). The fact that the lua
library is committed to bzflag's SVN make that much easier to do than to require an external
library dependency.

Re: lua bzfsAPI plugin

Posted: Sat Jan 03, 2009 11:47 pm
by F687/s
Wow, very nice. I've heard about the inclusion of Lua into trunk, but haven't heard much about implementation. Hopefully this will create some new plugin developers (that are currently afraid of C++).

Some random questions (related to the plugin):

* You say that Lua can now be included into ordinary .bzw files. Do the BZW files need a preliminary declaration (such as a "loadplugin" or BZFS command line option), or can they be seamlessly integrated into the file? I don't know, the "-loadplugin,dieHard,$HOME/bzfslua/bzfs.lua" declaration looked kinda vague...

* I assume that, even though Lua is included into BZW, that still doesn't make the files dynamic? Like, you couldn't make a moving box or anything? (Minds well ask...)

* Finally, are the Lua parts in the .bzw file interpreted by the client or the server? Or: Is Lua basically acting as a .bzw preprocessor (plus more)?

Anyway, it's good to see that we're all one step closer to 3.0...

Re: lua bzfsAPI plugin

Posted: Sun Jan 04, 2009 1:03 am
by trepan
BZFS plugins are entirely server-side. That should answer most of your questions.

Re: lua bzfsAPI plugin

Posted: Fri Jan 16, 2009 11:21 pm
by trepan
The server-side lua plugin was merged into the bzfs executable in SVN r19215.
That means that you can count on having server-side lua plugins regardless of
the build configuration (it also helps to speed up some of the callouts, and makes
it easier to share code with the client-side lua libraries).