Implementing a new script language

Implementing a new script language

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
Fnordia
Former Engine Dev
Posts: 425
Joined: 13 Aug 2004, 16:11

Implementing a new script language

Post by Fnordia »

One of the plans for the new unit format is to include a more advanced scripting language, and one that can be used for scripting more than just the animation of units.

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()
So far lua+luabind has been nice to work with, and it seems like a reasonable choice. Exposing the float3 class and the unitloader to lua only requires a few lines of code. But before I integrate it too far, I was planning to post this and see if there are any comments or ideas for choosing some other path.
Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

Post by Archangel of Death »

I have done some work with an integrated lua before (Homeworld 2). It is pretty much the basis of the entire data system in HW2. However, the files are stripped to only be able to do and have what they were meant to (eg, no adding in a previously non-existing line like "sheildsystem" into the .ship and linking it to something in the .anim animation scripting). This probably makes it more efficient, but lowers the power lua could have provided.

I'm hoping you can keep the lua as free of being hardcoded as possible. Now, we may not need (or want as a possibility) to be able to load exterior .dll's in a unit's scripting, but perhaps it would be useful to be able to load a custom weapons effects file.

Meh, I feel like saying more but am running short on time. That covers my thoughts well enough.
User avatar
GrOuNd_ZeRo
Posts: 1370
Joined: 30 Apr 2005, 01:10

Post by GrOuNd_ZeRo »

Fnordia, I urge you to keep support for .cob files, LAU might be way to complex for us simple modders to understand anytime soon and i'm sure we will need some very specific compiler for it...

It would be sweet if it supported some advanced features but i'm not too sure what will be possible, I still want support for customized flares, explosion and such, maybe custom models like 3DS files linked to a 3DO file which are UV mapped, triangular faced and Alpha textures...(i'm percistant aint I?)
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

What's the current idea about actually integrating this into spring?
I very much like to see things abstracted, I've looked into it, and I think the interfaces could be based CCobEngine and CCobInstance, so you'll have a IScriptEngine and IScriptInstance.
(On a side note, similar things could be done with C3DOParser and LocalS3DOModel)
Probably you were thinking something similar, but please let me know what the plans are before they are implemented ;)
User avatar
Tim Blokdijk
Posts: 1242
Joined: 29 May 2005, 11:18

Re: Implementing a new script language

Post by Tim Blokdijk »

Fnordia wrote:... 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. ...
The Linux port uses boost.
gcc >= 3.4 ... I suggest that you ask the Linux port mailing list about that one.
Won't be bad if you joined that list anyway.
User avatar
Agiel
Posts: 30
Joined: 21 Feb 2005, 15:53

Post by Agiel »

We're all going to have to learn lua anyway when supcom arrives, so why not get a head start? :wink:
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I attempted to bind the CGlobalAIInterface to lua using luabind and it didnt go well, I'm glad you seem to be makign progress, though be aware that lua doesnt have native support for classes and that class support has been added by luabind, though it still isnt as nice.

I suggest using squirrel, it's based on lua, designed for use in game environments, and has more features such as better class use, and the same easy syntax lua has albeit added to and simplified in some places, though you've said you've considered it, I wonder why you chose not to use it.

Although if you need grunt work binding interfaces with luabind, I dont mind doing it.
Fnordia
Former Engine Dev
Posts: 425
Joined: 13 Aug 2004, 16:11

Post by Fnordia »

I guess the main reasons I decided to try lua first was the simple fact that lua is more widely used (meaning more documentation and people who already know it etc), and that the luabind library looked nice. But squirrel would certainly be an option. Might give that a try as well.
User avatar
Ace07
Posts: 348
Joined: 21 Apr 2005, 20:46

Re: Implementing a new script language

Post by Ace07 »

Tim Blokdijk wrote:
Fnordia wrote:... 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. ...
The Linux port uses boost.
gcc >= 3.4 ... I suggest that you ask the Linux port mailing list about that one.
Won't be bad if you joined that list anyway.
Yes, I was wondering about that myself. If this won't work in Linux, we should try to find something that does work for Linux.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

If I'm not mistaken squirrel is already extremely similair to lua, maybe enough to run a large portion of basic lua scripts. Afterrall it's just a LUA VM that's been optimized with new features added to and minor syntax changes and additions.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

Fnordia, it's nice to see you guys showing the paths you're taking at that level. It helps people slowly getting into what's happening in the project at lower levels.
(although it may not be proving as usefull and help-gathering as it might :/)

As for Lua, on this kind of stuff i tend to think that looking at comercial games is the best starting point. I read that World of Warcraft (or Warcraft3?) uses Lua for scripting. If it is good enough for the mighty Blizzard, it surely must be good enough for Spring.
(possibly not so well adjusted to the job but still, most certainly, a good choice)

That said, i know nothing of Lua and can't help further.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

Fnordia any updates on the scripting implementation?
Keep us informed please :D
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

I'm curious too

Post by Pxtl »

I've been having a lengthy discussion in the main thread on the possibilities of multiplayer map scripting. Will the Lua system include this? I don't think map-scripting requires complex functionality, just ways to

a) declare victory
b) query/change attributes of various in-game units
c) create/destroy/change ownership of units

Combining that with the normal mod system and the normal Lua script capabilities would be all you'd need for Starcraft-style UMS maps. That, and you'd need to be able to associate a given map with a given mod and script.
Fnordia
Former Engine Dev
Posts: 425
Joined: 13 Aug 2004, 16:11

Post by Fnordia »

Ok, some lua stuff is now on sourceforge, and a simple testscript.lua is included in the 0.65b1 version. I implemented a simple mission but I ran out of ideas. :)

As of now it is a bit limited since the only script file that will be read is testscript.lua. But you can try it out and see what more functionality would be needed to make mapscripts and such.

Step two would then be to allow units to use lua scripts instead of cob. Cob script support will certainly remain though, I don't feel like rewriting all the xta scripts just to have them do the same thing. :)

I plan on doing it in an abstract way so that more languages could be added if there should be a need.. Haven't done any specific plans yet though. Also the current lua integration for startscripts is almost completely contained to its own files, so it should not be a problem to switch/add more languages for those things as well.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

lua, and Bos scripting are v. similair to C scripting in many ways, lua more so. I guess a simple scripter could do most of the covnersion work with the scriptor making the final necessary changes to complete the conversion, as long as each bos function was given an equivilant lua function.
Post Reply

Return to “Engine”