Adding new built-in functions to Lua

Post here if you want to help developing something for FAF.

Adding new built-in functions to Lua

Postby snooc » 12 Dec 2016, 18:32

Hi!

I've been working on a thing the last few days and today I got the first important thing working. In a few words: I hooked up a DLL in order to register new functions / libraries to Lua. Today I was able to do it the first time and run my helloworld() function while Supreme Commander was running.

It wasn't so easy because it seems those "slight changes" which are mentioned in the Supreme Commander Lua documentation are not so "slightly" after all - at least so far as I can tell.

However, the question I'd like to ask here is if this can actually be useful for you guys. Maybe I am not the first one who did it and the community decided against it already but I'd like to ask if this could be something of interest to us.

Some of you might have seen me asking in the FAF Chat a few things about programming an AI which can be controlled remotely. I am not sure yet if even though my hack works whether this is something doable but well - I can write arbitrary C functions, compile it into a DLL and run the code by calling it from Lua.

But maybe there are other things we're missing out in SupCom's implementation of Lua and maybe there's a way to do a few things about some restriction we're facing.

I already said too much. Please just let me know what you think about this. If the response is positive I'm willing to continue to work on it and of course share it with you guys. There's of course a lot more to say about this but first I need to know what you guys think.

BR; Stefan
snooc
 
Posts: 5
Joined: 12 Dec 2016, 18:19
Has liked: 3 times
Been liked: 2 times
FAF User Name: silentsnooc

Re: Adding new built-in functions to Lua

Postby Downlord » 12 Dec 2016, 19:44

That's cool! First restriction that comes to mind is that' we currently can't add new Server -> Game messages since the messages known to the protocol are compiled into the binary.

Second and related thing is, that we can't open sockets from within LUA, for whatever reason that would be required.

Thirdly, we can't mount (or reload already mounted) directories which currently makes it impossible to automatically download and add missing maps without restarting the game.

Another thing is the ICE-adapter we're currently implementing; it's currently a standalone binary that wraps the GPGNet protocol. In theory, we could build the ICE support straight into SupComFA. I that would give us any benefit, idk.

I'm sure there are plenty more and crazy things we could do, those are just the ones that came into my mind :-)
If you want to be hardcore, you could substitute the pathfinding algorithm ;-)

Either way, we're always looking for talented developers, another C/C++ developer is something that would be helpful, too!
Working on FAF is my passion. Most of you know me for the feature-rich Downlord's FAF Client, but I also program and maintain the FAF server. Visit my Patreon page to get some insights on my work.
Downlord
Councillor - DevOps
 
Posts: 226
Joined: 14 Jul 2013, 14:55
Has liked: 161 times
Been liked: 213 times
FAF User Name: Downlord

Re: Adding new built-in functions to Lua

Postby snooc » 12 Dec 2016, 20:25

Hi! :)

Glad to hear that this might actually be useful :D

I just like to stress that all I just did was a quite simply proof of concept. There are several things that might go wrong here. One of the things that appear to have changed in SCL (Supreme Commander Lua) is the way garbage is collected. I tried to include a compiled version of Lua 5.0.1 (which appears to be the version being used by SC) but as I tried to run the code on stolen structs I was faced with the problem that the original implementations for registering functions did crash the game. One would have to look into that and sort out what we can actually do and what not.

I was thinking about laying a foundation for others to implement their own Lua libraries. My helloworld() can actually be called with

Code: Select all
ext.helloworld()


inside Lua for example.

One thing that has to be mentioned is that for this hack I had to modify the executable. I know that this is not something one wants to do but it was necessary. There might be a way to not have to modify the executable by using e.g. WriteProcessMemory though.

I agree with you that indeed a few things could be done with this - we'd have to further investigate what's possible with that and what's not of course :)
snooc
 
Posts: 5
Joined: 12 Dec 2016, 18:19
Has liked: 3 times
Been liked: 2 times
FAF User Name: silentsnooc

Re: Adding new built-in functions to Lua

Postby PattogoTehen » 12 Dec 2016, 23:50

My FAF projects:
LiveStreamer Launcher, Online Replay Analyzer, Replay Syncer, Custom FAF client

Paypal: pattogotehen at outlook.com
PattogoTehen
Avatar-of-War
 
Posts: 70
Joined: 29 Aug 2013, 19:19
Has liked: 0 time
Been liked: 44 times
FAF User Name: PattogoTehen

Re: Adding new built-in functions to Lua

Postby snooc » 13 Dec 2016, 00:01

PattogoTehen wrote:http://forums.faforever.com/viewtopic.php?f=45&t=5757

https://github.com/FAForever/supcom-se/ ... /scse/scse


Oha .. I guess at some point I would have arrived at something that looked like this. Why is this not being used actually, or is it?

And how did they get all those addresses? XD https://github.com/FAForever/supcom-se/ ... Linker.cpp
snooc
 
Posts: 5
Joined: 12 Dec 2016, 18:19
Has liked: 3 times
Been liked: 2 times
FAF User Name: silentsnooc


Return to Contributors

Who is online

Users browsing this forum: No registered users and 1 guest