lua bzfsAPI plugin
Posted: Wed Dec 31, 2008 12:26 am
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):
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
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
options
-loadplugin libbzfslua.so,dieHard,$HOME/bzfslua/bzfs.lua
end
# block comments
lua
BZ.AttachMapObject('/*', '*/', function() end)
BZ.AttachMapObject('-/*', '*/', function(name, data) return data end)
endlua
/*
woot,
a multiline comment
thanks to lua
*/
box
size 10 10 10
end
lua
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')
end
end
return lines
endlua
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