PLUGIN: Lua for AGS

Started by Denzil Quixode, Fri 04/09/2009 19:30:22

Previous topic - Next topic

Calin Leafshade

Yes, that is precisely what it does.

Lua is not a language i personally like that much but it is *far* more flexible than AGSScript and since the plugin provides access to everything that AGSScript does there is really no reason to use standard ags script anymore. I am of the belief that AGSScript is quite literally obsolete at this point.


Crimson Wizard

But we would still have to have event callbacks in the AGSScript, like game_start, repeatedly_execute, object interactions?

Calin Leafshade

Yes, but as Denzil said higher up, it's easy to make a system whereby a lua script can subscribe to events from the main script.

Denzil Quixode

Quote from: Calin Leafshade on Sat 28/07/2012 17:02:34
since the plugin provides access to everything that AGSScript does
Not quite true - you cannot access object fields (as opposed to properties, which are really getter/setter functions in disguise). There's very few of those around now, mostly you access everything through properties, but I think there might still be a few odd things you can only do with fields.

AJA

Plus you can't call modules or plugins from Lua.

Glad to see someone else finally seeing the light, Calin. :)

Btw, I'm not sure whether it's AGS or this plugin but it takes quite a while to save a game in Barely Floating (see GiP thread for game info). If AGS saves a screenshot regardless of whatever the game settings are, then it might be AGS. But just as a heads up, if the plugin saving is in any way a slow operation, you might want to add some AGS system polling calls in there because the sound stutters whenever I save a game.

And what exactly is the problem with fields? Can't you just write wrapper functions to access them? Or is there no way to access them through the plugin API? Why do I feel like I've asked this question before... :P

Denzil Quixode

#85
Quote from: AJA on Sat 28/07/2012 20:25:50
Plus you can't call modules or plugins from Lua.
Oh, yes, that too. It should at least be possible to convert any script module to Lua, and I did start work on a tool to automatically convert any piece of AGS script to equivalent Lua code to help with that.

For plugins though... well, it migbt be possible to one day achieve this, but it would take quite a bit of work:

  • I have no idea if the GetScriptFunctionAddress() works with plugin-imported functions, obviously that has to be the case
  • In order to call arbitrary C/C++ functions that are not known to the runtime plugin compiler at compile-time, the Lua plugin would need to use a special FFI library like libffi. (I haven't tried this before, I'm not sure how much work it would be, or how cross-platform.)
  • In order to find the other plugin's function signatures, the AGS script headers would need to be parsed and processed to extract them. (Luckily there is the C# module "SPAGS" I made that should help with doing stuff like that, though.)
Quote from: AJA on Sat 28/07/2012 20:25:50
Btw, I'm not sure whether it's AGS or this plugin but it takes quite a while to save a game in Barely Floating (see GiP thread for game info). If AGS saves a screenshot regardless of whatever the game settings are, then it might be AGS. But just as a heads up, if the plugin saving is in any way a slow operation, you might want to add some AGS system polling calls in there because the sound stutters whenever I save a game.

There is certainly a bit of processing going on when it serializes the Lua state. Part of the problem is I've never had a realistically large real-world test case project myself to experiment with, so it's quite possible you're seeing it under more strain than I ever have. I will certainly look into good places to put some PollSystem() calls, anyway.

Quote from: AJA on Sat 28/07/2012 20:25:50
And what exactly is the problem with fields? Can't you just write wrapper functions to access them? Or is there no way to access them through the plugin API?
While checking up on the documentation in reply to this I just noticed the GetGameOptions() function in the plugin API that I somehow missed before, so for game options it seems like it should be possible to write those wrapper functions! Sorry for not spotting that before. I'll put that on the todo list.

(In general though, there's no documented way to access them. Admittedly, I am already working with undocumented things in the plugin API, like using "GetScriptFunctionAddress" to get the addresses of variables rather than functions, and the odd way that "float" values are passed around internally as function parameters/return values in AGS. For both of those I was using information I found posted on the technical forum, so it was already kind of unofficially established, but I couldn't find anything about struct fields.)

Dualnames

Further discussion has been moved to HERE
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Denzil Quixode

#87
A new version (edit: another new version) of the plugin is now available from http://lua-for-ags.wikispaces.com/Downloads

The main changes:
  • You can now access game variables (ags.game.text_shadow_color, ags.game.total_score, etc.) and character fields (ags.player.on is probably the only useful one). Values that can only be 0 or 1 are exposed as Lua booleans, so make sure you do things like "if ags.player.on then..." instead of "if ags.player.on == 1 then..."
  • You can queue up a call to a global script function that takes 0, 1 or 2 int parameters, to be executed as soon as the current script has finished, by using:
    Code: Lua
    ags.queue('MyGlobalFunc' [, intparam1 [, intparam2 ] ])
    ...or to a room script function, with
    Code: Lua
    ags.Room.queue('MyRoomFunc' [, intparam1 [, intparam2 ] ])

JJS

I have a quick question on compiling the source: Is the version of Lua used (5.1.4) critical or would the plugin also work with Lua 5.2.x?
Ask me about AGS on PSP, Android and iOS! Source, Daily builds

Denzil Quixode

Quote from: JJS on Mon 30/07/2012 10:43:38
I have a quick question on compiling the source: Is the version of Lua used (5.1.4) critical or would the plugin also work with Lua 5.2.x?
Unfortunately the Pluto serialization library that this plugin's save/load system relies on is extensively tied to the internals of 5.1. If there is a 5.2-compatible version of Pluto I'm not aware of it.

JJS

Ok, thank you! It is not a problem to use 5.1.4, I just wanted to know what version I should use as a base because they need different patches.
Ask me about AGS on PSP, Android and iOS! Source, Daily builds

Joseph DiPerla

Joseph DiPerla--- http://www.adventurestockpile.com
Play my Star Wars MMORPG: http://sw-bfs.com
See my Fiverr page for translation and other services: https://www.fiverr.com/josephdiperla
Google Plus Adventure Community: https://plus.google.com/communities/116504865864458899575

JJS

#92
I got the plugin running on Android. The changes to the plugin source are in here: https://github.com/jjsat/Lua-for-AGS

Changes are mostly for making GCC happy and enclosing the windows.h include and the MessageBox code in #ifdefs. Also I commented out the unused mutex as it doesn't seem like it is used anywhere.

Can you review the code and maybe merge it into your repo if it doesn't break anything?
Ask me about AGS on PSP, Android and iOS! Source, Daily builds

Denzil Quixode

Great work JJS! Thanks! I've merged the changes, it all looks reasonable and it compiles without a hitch. (I can't remember why I ever had that mutex...)

Calin Leafshade

#94
A request:

Line numbers in the editor please.

Edit: Also a way to enumerate the scripts in the store would be nice.

Denzil Quixode

I've added the line numbers to git.

Here's a built version (just the editor plugin): download

Calin Leafshade

Thanks,

with regards to the script store all would really be needed is an array of the filenames and an int somewhere for the count.

Code: ags

int i;
while (i < Lua.ScriptCount)
{
    Lua.RunScript(Lua.ScriptNames[i]);
    i++;
}

Denzil Quixode

It's slightly complicated by the fact that the scripts can be put in folders (and really are stored in this folder hierarchy internally, not an array).

Calin Leafshade

Hmm well the filename could just return the relative folder structure.

So a file at lscripts/folder1/lua1.lua would return "folder1/lua1.lua"

I don't think having a special tree structure in this case is that necessary. If the user wants to rearrange the data at runtime they can do so.

Denzil Quixode

I've added Lua.ScriptCount and Lua.ScriptNames[]. Here is the dev version of the runtime plugin with this change: download

SMF spam blocked by CleanTalk