Adventure Game Studio

AGS Development => Engine Development => Topic started by: Calin Leafshade on Fri 27/07/2012 01:16:27

Title: [DISCUSSION] Integrating Alternative Scripting Languages (was: Lua for AGS)
Post by: Calin Leafshade on Fri 27/07/2012 01:16:27
Dualnames: To be merged with topic www.adventuregamestudio.co.uk/yabb/index.php?topic=46493

I think we should consider generalising it and making an interface similar to the the FontRenderer one. I don't think it would be *that* hard. AGS provides serialisation methods and stuff in the plugin API so it would just be a matter of taking what has been learnt from AGS-lua and applying it more generally. Most of the building blocks are already in place.
Title: Re: Re: PLUGIN: Lua for AGS
Post by: Crimson Wizard on Sat 28/07/2012 20:39:47
I am actually wondering if there's a way to fully substitute AGSScript with Lua.
To make myself clear - I am not thinking Lua is the best choice (never used it actually) nor that AGSScript should be thrashed right away.
My thought is that since there's an alternate scripting language why not make it fully integrated without AGSScript as an intermediate.
There was a discussion about this earlier (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=46157.msg622114#msg622114).
Not sure if that's easy task though. Just something to keep in mind.
Title: Re: Re: PLUGIN: Lua for AGS
Post by: Joseph DiPerla on Sat 28/07/2012 20:52:25
I would think that maybe adding it as a seperate scripting system in AGS all together would be good, while keeping AGSScript would be nice. For instance, in the scripts editor, you have Global.ASH and Global.ASC which is the default language for AGS. However, when adding a script, perhaps you can now have an option of either adding AGSScript or LUA scripts (AGSLUA). You can make calls between the two types of scripts and you can also, possibly do externs and such. As far as events, such as repeatedly execute, it would only be allowed to be called within one of the scripts. You can not have one variation existing in ASC and the same one in LUA. Its either or. If it does exist in both, AGS will run the one found in ASC.
Title: Re: Re: PLUGIN: Lua for AGS
Post by: Calin Leafshade on Sat 28/07/2012 21:47:44
Considering the (relative) ease that Denzil managed to implement Lua, I think it would be stupid not to go in this direction.

I am of the opinion that expanding the plugin interface is the way to go here, specifically giving plugins access to hook onto game scripting events. Implementing a defacto language or improving the current scripting language which is not fit for purpose considering the competition seems counter productive. I realise that i have somewhat changed my tune in this regard but on consideration and on seeing what this Lua plugin is capable of it seems to be an inescapable conclusion. When CJ implemented the compiled language CPU cycles were at a premium. Now that is not the case and things like strongly typed variables, pointers and c style string formatting just seem silly in a scripting environment like this.

I mean think about this. *All* our complaints about AGSScript (passing structs, delegates, resizeable collections, encapsulation, inheritence, easy number casting) are fixed here and this plugin sat with relatively little attention. This plugin is the *best* thing to happen to AGS since i've been here. We should capitalise on it and learn from it.
Title: Re: Re: PLUGIN: Lua for AGS
Post by: Crimson Wizard on Sat 28/07/2012 22:04:20
Quote from: Calin Leafshade on Sat 28/07/2012 21:47:44
I am of the opinion that expanding the plugin interface is the way to go here, specifically giving plugins access to hook onto game scripting events.
Do you mean registering callback that is called along/instead of default event handlers?
JJS mentioned he is to integrate this plugin in his portable engine. He may update plugin interface perhaps. I will check too if I get time.

EDIT:
There's RequestEventHook function in plugin API. But it allows hooking to very limited number of events, mostly room events (enter/leave) drawing and loading events.
Also, plugin callbacks are run explicitly in the engine code. Adding more hooks this way will require adding calls throughout the engine. That should not be difficult, but I don't like it this way. Perhaps there should be an extendable implemenation. Uh, but that's rather for Engine development board.
Title: Re: Re: PLUGIN: Lua for AGS
Post by: SpeechCenter on Sat 28/07/2012 23:25:03
This plugin is certainly possible thanks to both AGS and Lua's flexibility and of course ingenuity.

I believe the remaining limitations here occur because both AGS and Lua compile to different intermediate languages. Meaning, if we were to make sure all languages can compile to the same intermediate language then we'll have total flexibility on this. It would make the engine agnostic to the actual language.

I see here 3 routes:

Another part is making sure the editor allows different languages, this is much easier to do once we have a documented IL that has been proven to work with more than one language. One possibility is to extend the plugin interface to support this and allowing the editor to have a standard interface to all its scripts regardless to their language.

Anyway, this requires technical analysis, I'll be happy to take part. My relevant background is C, C++, x86 assembly, text parsers and more recently, C#.
Title: [DISCUSSION] Integrating Alternative Scripting Languages (was: Lua for AGS)
Post by: Denzil Quixode on Sat 28/07/2012 23:55:48
(Edit: No longer relevant now the thread is split)
Title: Re: Re: DISCUSSION Lua for AGS
Post by: Calin Leafshade on Sun 29/07/2012 00:01:03
I'm not sure that's the best way to approach it.

Compiling Lua to a bytecode IL in the editor removes some of the benefits of Lua (runtime reloading of scripts for instance).
It also raises the level of entry for new language implementations.

Also, surely keeping the language implementation as close to the official release is better since new versions can be dropped in on release.

I guess the question we need to ask is that is the overhead of a plugin interop worth the ease of making new languages available.
My thought is probably yes since speed is not of primary importance but others may feel differently

Edit: Also, yes perhaps a new thread might be useful. Can a mod split out the thread or something please?

Title: Re: Re: DISCUSSION Lua for AGS
Post by: Crimson Wizard on Sun 29/07/2012 00:10:15
I feel it's better to focus on extending plugin interface for now.

Compiling from lua (or other language) to AGS IL is a totally separate task, and will take more time to discuss and implement. Besides, as Calin mentioned, it will add restraints to external language's features and efficiency. It is also a separate way of making scripts. In fact those two ways may co-exist.
Title: Re: Re: DISCUSSION Lua for AGS
Post by: Denzil Quixode on Sun 29/07/2012 00:47:15
Lua requires various things that I'd think would be very difficult to make work in an IL that wasn't specially designed for it, even ignoring dynamic compilation:
Title: Re: Re: DISCUSSION Lua for AGS
Post by: Denzil Quixode on Sun 29/07/2012 01:30:30
Quote from: AJA on Sat 28/07/2012 20:25:50
If AGS saves a screenshot regardless of whatever the game settings are, then it might be AGS.
I'm not sure that it does, but another possibility just occurred to me: do you ever use Room.GetDrawingSurfaceForBackground()? I think if you do that, at least while you stay in that same room, the edited background would need to be stored in any savegame data too.
Title: Re: Re: DISCUSSION Lua for AGS
Post by: AJA on Sun 29/07/2012 11:15:34
Nope, there shouldn't be any dynamic sprites or surfaces since all I use them for is rendering dialog text, and they're all deleted before you can save. (Unless they're in a coroutine but that's a rare case.)
Title: Re: [DISCUSSION] Integrating Alternative Scripting Languages (was: Lua for AGS)
Post by: SpeechCenter on Sun 29/07/2012 18:31:42
Quote from: Calin Leafshade on Sun 29/07/2012 00:01:03
Compiling Lua to a bytecode IL in the editor removes some of the benefits of Lua (runtime reloading of scripts for instance).
It also raises the level of entry for new language implementations.

Also, surely keeping the language implementation as close to the official release is better since new versions can be dropped in on release.
It's true, but there's more than one option here (I mentioned 3 and there are probably more). Let's cover what are the requirements before jumping to the solutions (so sorry for doing that earlier)

Here are some features that we need to decide if they are required (not saying they are, just questions I have here and the list of feature requirements should be longer eventually):
Title: Re: [DISCUSSION] Integrating Alternative Scripting Languages (was: Lua for AGS)
Post by: Clarvalon on Tue 31/07/2012 08:52:42
De-coupling the scripting from the game engine via an interface would seem to be the option providing the most flexibility going forward.  I've done something similar with XAGE:  http://youtu.be/0Ke49lJ8R94

The argument could also be made that having AGS Script tightly integrated in the IDE is one of AGS Editor's strengths.  As it stands, AGS is a tight, standalone package.  Potentially, beginners may be confused or deterred if forced to maintain their game scripts outside of the main IDE.