I've looked at a few alternatives such as squirrel, angelscript, gamemonkey and lua, and I decided to start testing lua together with luabind for integrating with the c++ code. Lua has support for stuff I want such as classes and coroutines, and since it's the most widely used there's a lot of documentation etc which is nice for those who are interested in scripting. An alternative to luabind would be luaplus, but from what I understand it's windows only.
It's also not completely without drawbacks of course. The current garbage collection in lua can supposedly freeze up the application at times, but lua 5.1 is going to feature a better system. Luabind also requires boost headers to be installed. I believe the linux port already uses boost though, so it would probably be required at some future point anyway. And on a related note, luabind also currently does not compile on gcc >= 3.4. But this is said to being worked on.
To try it out, I have started with implementing support for writing new startscripts in Lua. (The scripts that can be selected when starting spring.exe directly). So far enough functionality has been exposed to create a script that can place units on the map. Here's what such a script looks like currently.
Code: Select all
-- Create a subclass of the native spring class Script
class 'TestScript' (Script)
-- Pass the script name to be displayed to the parent constructor
function TestScript:__init() super('Lua testscript')
end
-- This function is executed every simulated frame (30 times/sec)
function TestScript:Update()
if gs.frameNum == 0 then
self.pos = float3(1800, 10, 2910)
unitLoader:LoadUnit("ARMFLASH", self.pos, 0, false)
elseif gs.frameNum == 1 then
print("Spawned flash at", self.pos)
end
end
-- Instantiate the class so that it is registered and shown
testScript = TestScript()