Page 1 of 1

Squirrel String Library

Posted: 18 Oct 2009 22:34
by Zutty
Hi all,

This question is mainly aimed at Yexo and the other developers.

Since the Squirrel standard math library was enabled, could we also have the string library. It would be useful to have regular expressions, among other things.

I could have a go at writing a regexp parser myself (perhaps for the common library project), but before I bother I'd just like to check if the above is a possibility.

Thanks

Re: Squirrel String Library

Posted: 26 Jul 2013 12:28
by Wormnest
I know this is an old topic but I'm interested in knowing if this has ever been considered for inclusion.
Personally I would like being able to use the format function. It would help to make formatted strings easier.

Re: Squirrel String Library

Posted: 27 Jul 2013 20:48
by krinn
I don't think anyone is really interrest in doing a complex output system for an API that output nothing :)
Well, ok, except GS that may output a few more now (that's still really low), NOAI output nothing by itself (to user i mean, outputing to console or signs is not really something for a user).

Try look at that lib http://dev.openttdcoop.org/projects/ailib-string
But i don't think any regex function exist, i can only think of machinweb or zuu that could have made some functions to handle strings, check their libs.

Re: Squirrel String Library

Posted: 27 Jul 2013 23:02
by Wormnest
The thing is that Squirrel already has a string library thus no one really should need to work on that. It just isn't enabled in OpenTTD.
Of course I don't know if there are parts of that library that would need to be adapted or whether there are other implications to using the library. If there are I would be interested to hear them at least.

Re: Squirrel String Library

Posted: 28 Jul 2013 22:03
by Zuu
1. Rethink what you want to do
OpenTTD comes with a string system with support for translations. To use it you define a string using an identifier and some text in lang/english.txt. The text can contain place holders for data. Data for the placeholders is sent to OpenTTD when you construct a GSText object or by calling AddParam on the object. Passing a company ID to the {COMPANY} placeholder makes OpenTTD automatically insert the company name for the place holder.

So for any string that are shown in the user interface should use the language file and GSText rather than raw string manipulation.

For AIs or printing debug messages in GSes, you may still want to do raw sting composing. In that case, see the available library methods below.


2. Library methods
If you still think that you want to manipulate raw strings, I've here tried to explain what SuperLib provides:

SuperLib.DataStore - contains methods to encode data into strings as well as helpers for storing strings in the name of eg. vehicles and stations (and handle the constraints by OpenTTD that station names need to be unique).

SuperLib.Helper - contains a limited set of string helpers that I've added into SuperLib for tasks not handled by the Squirrel string object itself.

Last, there is also AILib.String as pointed out above.