I need a Spring.Rehost command!

I need a Spring.Rehost command!

Requests for features in the spring code.

Moderator: Moderators

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

I need a Spring.Rehost command!

Post by zwzsg »

I improved my integrated launcher. I moved the code that invent a random skirmish and write the corresponding startscript from the C++ of an out of Spring .dll, to a Lua widget inside the mod. However, there is one last blocking point: Spring is currently unable to relaunch itself, and I still have to use an external .dll just to run "Spring.exe myKPstartscript.txt". This is bad because:
- Not portable, only run on Windows
- The running of .dll by widget will soon be outlawed for security reason.

I would need a single Lua command, Spring.Rehost("somefile.txt"), and then I can have my Single Player Lobby all inside my mod, clean and portable.

It should be executable by both widgets and unsynced gadget.
The argument should be the filename of the startscript.txt. By the way don't remove me file:write please. It would be nice if it could also directly read a startscript from the mod archive, in addition to a file in Spring's root folder.

Such a command would also greatly help in making campaigns.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: I need a Spring.Rehost command!

Post by Tobi »

I'd suggest that instead of a filename it takes the entire startscript as a string, this way you don't have to bother about writing it to a temporary file at all.

(A version taking filename could very easily be implemented in Lua itself if the engine provides a version which takes entire startscript as string. With the added advantage that you can choose whether you load the script from mod, map, or raw filesystem.)
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: I need a Spring.Rehost command!

Post by zwzsg »

I had the notion that handling super long strings was bad, and constructing them by appending small bits after small bits even worse.

Otherwise yes.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: I need a Spring.Rehost command!

Post by Tobi »

zwzsg wrote:I had the notion that handling super long strings was bad, and constructing them by appending small bits after small bits even worse.
Handling super long strings is only bad when they are longer then about 2^23 bytes (8M), IIRC (may be mistaken a few factors of 2).

Constructing them by appending small bits is O(n^2) algorithm yeah.

Better use:

Code: Select all

local s = {}
s[#s+1] = "first part"
s[#s+1] = "second part"
s[#s+1] = "third part"
-- etc.
s = table.concat(s)
table.concat concatenates in a smart order (small bits together first) so it has a lower algorithmic complexity.

(And yeah, I realize the s[#s+1] can be optimized even further, but I doubt it matters.)
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: I need a Spring.Rehost command!

Post by lurker »

16M, because of the implicit 1.xxx
But that's only for splitting where you need to worry about precision.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: I need a Spring.Rehost command!

Post by zwzsg »

So, will I have it, or is any development on my Lua Single Player battleroom doomed to the trashbin? (Since the .ddl exploit has been fixed it won't work without rehost command.)

Also, if you broke startscript syntax again, link me the new specs. Current test build says: Could not find 'gamedata/parse_tdf.lua' code. Ok, apparently, that bug is not related to starscript syntax change, but to "somewhere around" SpringData config key being empty. Somehow, SpringLobby manage to get Spring.exe running fine with that key empty, but drag and dropping a startscript over Spring.exe, requires it to be set to Spring folder. Startscript syntax still changed however since I got a gameover on start. Apparently there is now an [AIx] section for bots and, and god now what else. Hmm, I now got both my Kernel_Panic_3.2_Launcher.exe and my widget thing to write startscript accepted by test build spring.exe, so nevermind.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: I need a Spring.Rehost command!

Post by AF »

the start script is being read in as lua anyway? so couldn't there be an option to pass a table and not a string instead? That way all you need is a default lua script to generate a table then modify it at runtime in memory by changing the values in it then pass it to the engine.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: I need a Spring.Rehost command!

Post by Tobi »

It isn't read in as Lua (yet).
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: I need a Spring.Rehost command!

Post by zwzsg »

AF wrote:That way all you need
I already have done the whole generating and writing a startscript from a gadget, so it wouldn't take more time to use what I already have than to rewrite it to conform to a new format.

Would appreciate if startscript syntax/format/standard stopped changing btw.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: I need a Spring.Rehost command!

Post by AF »

You wouldn't need to handle syntax etc if it was a lua table, and you wouldn't run into the issues regarding read only file systems too.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: I need a Spring.Rehost command!

Post by zwzsg »

AF wrote:You wouldn't need to handle syntax etc if it was a lua table
Yes, because Lua has no syntax, and because Lua code write itself, of course.
AF wrote:you wouldn't run into the issues regarding read only file systems too.
I am fine with Tobi proposal of long string.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: I need a Spring.Rehost command!

Post by zwzsg »

Image

I'd really like such a Spring.Rehost(str) command.

Think of all the amazing things we could do with it:
- A single player lobby as a widget, integrated into Spring (my widget is all ready, it just need that command).
- Very pretty skirmish menu, since we can use all the OpenGL Lua command: I could make semi-transparent animated 3D menu, I could use unit model as bullet point with gl.UnitShape, I could run an AI battle or whatever game scene in the background, etc...
- Easy to write skirmish menu, since we have so many Lua coders around. I'm sure I won't be the only one to write one.
- Dumb newb that don't know they are not supposed to run Spring.exe would not get the bad impression left by the hardcoded startscripts.
- Missions that launch other missions, forming a campaign.
- Dynamic campaign, since we have access to the full game state when we decide relaunch it, we can branch to one mission or another, or even write a startscript customised to how the previous game ended (like count team alive, count resources, count unit alive, and write a startscript that give them back).
- No external application adding mess in the Spring folder: The SP menu of each mod would be contained within the mod archive: It's clean, and make it impossible to break by missing a file.
- Fully cross-platform with zero porting work, since it would be entirely done within Spring Lua.

So please, give me that Spring.Rehost(str)
Whether "str" is the startscript.txt filename or the content of the startscript as one huge string, I don't care, do as you want.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: I need a Spring.Rehost command!

Post by Argh »

Check the commits, looks like you got your wish!

Sooo... anybody want to pool resources and build a solid launcher / configuration toolset and UI?
Auswaschbar
Spring Developer
Posts: 1254
Joined: 24 Jun 2007, 08:34

Re: I need a Spring.Rehost command!

Post by Auswaschbar »

I like the picture.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: I need a Spring.Rehost command!

Post by zwzsg »

I'd really like to test it, as I am currently writing widgets making use of it, but Spring stopped working for me between 0.79.0-524-g2e8ff49 and 0.79.0-541-g892ce49. And I'm being told it won't get fixed unless I learn to compile Spring and to debug it myself. :(

How hard would it be to make me a builld of Spring with just that Lua call ported back on an older Spring version?

Edit: dizekat helped me narrowed it down to one single commit:
I tested spring_exe_0.79.0-532-gb9bc44f.zip and it works
I tested spring_exe_0.79.0-533-g687f388.zip and it fails

Edit: Ok, finally Test Build works on my ATI, and I could that new command it.
Spring.Restart("-w",VFS.LoadFile("Kernel_Panic_script.txt")) works! Woot!

Spring.Restart("",VFS.LoadFile("Kernel_Panic_script.txt")) and Spring.Restart("Kernel_Panic_script.txt","") make it reload to the hard-coded Spring Menu.

What does -w stand for? Where do I find list of Spring.exe option?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: I need a Spring.Rehost command!

Post by hoijui »

Code: Select all

spring --help

Code: Select all

-w [ --window ]          Run in windowed mode
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: I need a Spring.Rehost command!

Post by imbaczek »

on windows, you'll need to do

Code: Select all

spring --help >help.txt
to see anything.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: I need a Spring.Rehost command!

Post by zwzsg »

hoijui wrote:

Code: Select all

-w [ --window ]          Run in windowed mode
I use:
Spring.Restart("-w",VFS.LoadFile(ModSpecific.ScriptFileName))
And it works and Spring doesn't change to windowed mode.


When I use:
Spring.Restart("",VFS.LoadFile(ModSpecific.ScriptFileName))
Spring instead of using the specified scipt, restart to hard coded Spring menu.


But then I used:
Spring.Restart(" ",VFS.LoadFile(ModSpecific.ScriptFileName))
And it worked too.


So I suppose the problem is that Spring.Restart doesn't like its first argument to be an empty string.
Auswaschbar
Spring Developer
Posts: 1254
Joined: 24 Jun 2007, 08:34

Re: I need a Spring.Rehost command!

Post by Auswaschbar »

Code: Select all

const string arguments = luaL_checkstring(L, 1);
const string script = luaL_checkstring(L, 2);
Is this the right order to get strings from lua stack? I mean, is luaL_checkstring(L, 1) the first and luaL_checkstring(L, 2) the second argument?
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: I need a Spring.Rehost command!

Post by Kloot »

Yes, lua_f(L, i) always refers to the i'th Lua function argument on the stack.
Post Reply

Return to “Feature Requests”