In earlier C4Script versions, there were multiple variants of expressions,
all followed by the same operator options, but nowadays everything is more
uniform.
This bug manifested itself in mysteriously growing PropLists with nil keys.
Some usages of Clear were simply to clean the newly-allocated table, and
need to continue to do so.
It isn't clear whether that call is necessary since the C4AulScriptEngine
constructor already does this, but it is clear that duplicating the call
all over is a bad idea.
This allows the removal of quite a few return C4Void();.
Also stop pretending that Nillable<void> is the same class as Nillable<T>.
Its only function was as an implementation detail for C4Void, which doesn't
need any implementation details anymore.
This avoids duplication of code in C4AulObjectFunc and C4AulEngineFunc
at the cost of boilerplate code working around the lack of partial
function template spezializations.
Instead of ThisImpl and ExecImpl, we could have multiple C4AulEngineFunc
spezializations deriving from a common template, but that would require
even longer and duplicated boilerplate.
This allows one to use the C4Value constructor instead of
C4ValueConv. To avoid unintended implicit conversions like
const char * to bool, add a private template constructor that
catches everything not in the list of intended constructors.
In the long term, there is no reason DirectExec should be concerned with
C4AulScript/C4ScriptHost. In the meantime, the lookup code from Fneval can
be moved into the function.
This allows eval in scenario script to access scenario script locals, but
that seems harmless.
Instead of tracking the status with a variable, simply test the loop-end
condition directly, and reduce code duplication between empty and non-empty
array contents.
Most of the changes are for exception safety. The parser references the
function stored in Fn when the function body contains a syntax error, so
the function has to stay around. In order to avoid memory leaks, store the
function and its containing proplist in their destinations before they get
fully parsed.
This doesn't allow functions directly in static constants or arrays.
Future work: Putting the owning proplist in the scope chain.
The C4AulScript containing the source of the function was already mostly
used to get the relevant proplist or available from context. This will
allow more than one proplist plus the global one per scripthost to contain
functions.
Apparently, this wasn't done already because of compatibility concerns. The
beginning of a release cycle is the perfect moment to finally complete the
prevention of using deleted objects from script.
Min/Max with array parameter will return the smallest/largest value of
all elements of the array. If any array element is not an integer, nor
convertible to integer, the function will fail.
This prevents a crash when an incompatible engine function is used as an
engine callback function.
Unfortunately, this breaks any scripts that have wrong type information in
engine callbacks and only worked because those were ignored.
The engine has a few more usages of the operators, but they don't look
prone to overflowing. The other operators in Script already used SetInt,
which always truncates to 32 bit.
This was used to name snapshot releases of the Network2 branch, and has
seen almost no use since.
C4ENGINEINFO(LONG) was a duplicate of C4ENGINENAME and C4ENGINECAPTION.
Translate() used to select the script which it checked for translations
before actually looking up the string key. Change it so if the object
the context of which it was called in doesn't have a matching
translation, the string table of the script containing the call is used
instead.
Getting the error summary written to the log/console automatically may
be useful for general game usage, but when testing Aul we just end up
with thousands of useless messages in the output. Let the caller log the
message if it's really desired.
The C++ standard library comes with perfectly fine implementations of
these functions, so there's no point in reimplementing them just for the
hell of it.
We already require support for std::unique_ptr, which itself requires
support for rvalue references. As such, we know we can use rvalue
references, and thus don't have to keep carrying dead code around.
Instead of just writing the raw string to stderr, escape them first so
newlines and other control characters don't result in strangely
formatted output.
The shapes library has such pointer chains. The leaks were getting pretty heavy because they included pointers to C4AulFuncs, which kept a lot of parts of the script engine and string tables in memory.
The string table of System.ocg scripts (except the global System.ocg) pointed to nowhere after the initial load phase, but is still required for reload. Added a ref counting option to keep these string tables alive.
The desync was caused by PropList->GetProperties returning the properties in an arbitrary order. They are now sorted first.
The debug logs are left in place, because I assume that I will need them again and they prove to be helpful.
While none of the mismatches were having a side-effect, this silences a
number of -Wreorder warnings which were drowning out potentially
important diagnostics.
Example: this.EditCursorCommands = ["Explode(20)"] on an item will offer a menu entry to explode the object. Commands may be either strings or function pointers, but function pointers will always be called by name.
src/script/C4Script.cpp:159:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (long i = 0; i < sizeof(values) / sizeof(*values); ++i) \
^
I would prefer to render the models for speaker portraits directly. However, it seems like it's not currently possible to clip or render models to offscreen surfaces.
The distinction between the "aul" and "non-aul" parts of
the script engine are mostly historical accident, and the
current organization of the source code does not use
sub-subdirectories. I'd like to keep it that way.
This reverts commit 69ba06b8d0.
Par() calls and '...' in function calls make functions take varargs
without this being obvious from the header. ExtraWarn about this so people
who care about it can add an ellipsis to the parameter list.
Accepting an ellipsis as the final parameter in a function declaration
makes it immediately obvious that the function can take a variable number
of parameters
If an object moves and other objects are attached to its SolidMask, only objects in front of this plane are moved along with it. Defaults to Plane if zero.
This makes C4Script consistent with C-based languages, and current usage
on master shows that in the majority of cases, the author expected to have
to place a semicolon after the loop anyway.
There have been some bugs and crashes related to unwanted deep comparison (e.g. in the maze scenario). Scripters very rarely need deep comparison, so it should not be the default for the most commonly used operator.
This also changes behaviour of GetIndexOf to do pointer comparison.
This change has Guenther's seal of approval.
This is mostly to prevent crashes when prototypes are deleted.
Also change proplist savegame format to not include the constant flag - all
constant proplists are not stored in savegames anymore, but recreated from
the game data. Store the prototype at that position instead.
Factor the common if (TokenType != t) UnexpectedToken() into a function.
Write the end-of-list-or-comma as one if and one Match instead of a long
switch-case-statement.
CheckParTypes now requires that the parameter array passed in is long
enough, just like Exec does. Luckily, FnCall has a ParSet, which is always
long enough.
The property can be used to give GUI windows a margin. Either the same margin in all directions (Margin = "1em") or different margins (Margin = ["1em", "2em", "10$", "0.5em"] - [left, top, right, bottom]).
This was solved via Target+Visibility before, but is such a main feature (more guis will be for a specific player than for everyone) that it legitimates an own property
As discussed in http://forum.openclonk.org/topic_show.pl?tid=2917, I
have merged all copyright notices into a single file and referenced that
merged file from each source file.
For the updated source files, the timeline has been split into three
parts:
1. Pre-RWD code (before 2001)
2. RWD code (2001 through 2009)
3. OpenClonk code (2009 and later)
All pre-RWD copyright notices have been left intact, as have RWD-era
copyright notices where the file did not have a RedWolf design copyright
notice but only individual author ones. All copyright notices of the
OpenClonk era have been replaced by a single notice ranging from the
first recorded year to the current year (2013). Mape code did not get a
OpenClonk Team copyright notice because it is somewhat separate from the
main OpenClonk codebase and has only been touched by Armin Burgmeier.
Turns out changing prop list numbers while they are still indexed by number in the hash map was a bad idea. Existing prop lists are now de-numbered, pushed to an external shelve and re-numbered when added after section load.
The new type C4TimeMilliseconds behaves for the most part like a uint32_t but is overflow-proof in comparisons.
In some places, a 0-value (or uint_max) of the variable storing the time had the special meaning "not set yet". This has been resolved by having it as a pointer to C4TimeMilliseconds with NULL meaning that it has not been set yet.
When reloading a function, C4AulParse didn't reset the parameter count.
This resulted in the function's ParCount to eventually increase above
C4AUL_MAX_Par, at which point parameter type checking would access
invalid memory.
This might make life easier for people who transition from Landscape.txt.
For new maps, lines should probably better be drawn using MAPALGO_Poly in a loop. This gives you more control over individual line widths, angles, etc.
fInternal basically acted as a reverse "evil bit" as in RFC 3514: when
set, the engine would not do any checks on the script contained in the
control packet, nor log the script (visibly in game; the packet log
would of course contain the packet). A malicious game client thus would
be able to inject arbitrary script without people (immediately) noticing
anything was amiss.
As of this patch, only the host is able to execute arbitrary scripts,
and those will be shown in the message board for all players to see.
This privilege can be irrevocably disabled in network games by any
client by using the "/nodebug" message board command.
Closes#936.
While fInternal-flagged script controls may be useful for debuggers to
evaluate watch expressions because they don't get shown ingame, they
also bypass all checks the engine does and as such are a nightmare in
network play.
Part of #936.
This is mostly for the benefit of savegames, which rely on being able to
save scenario functions as Scenario.Prototype.*, but also removes an
opportunity to break things.
C4StringTable::RegString modifies the provided StdStrBuf. Use FindString
instead, since GetPropertyByS reliably returns failure for a
freshly-registered string anyway.
excNotFound is used to signal that the end of a list is reached. But these
error conditions in C4Value::CompileFunc signal some logic error, not
finding an end-of-list marker instead of a C4Value.
The parser does not know whether the constant proplist it is about to fill
is missing because it was overwritten by a later local/constant, or because
the preparser was interrupted by a script error and didn't store its
proplist. Thus, the parser cannot simply give up at that point, and in
order to keep things simple it creates a throwaway proplist. This proplist
was thrown away too soon, though.
Thanks to Zapper for the testcase.
C4AulParse::Host is now only used for local variables and named functions.
Global directexec functions have neither, so they won't need a scripthost
at all anymore.
The missing break meant that the freshly created copy of the proplist would
get overwritten by the original, which was thankfully caught and announced
with "internal error: constant proplist has the wrong parent".
Thanks to Zapper for the testcase.
This makes functions independent of their "Code Owner"s, which removes the
necessity to maintain that connection and carefully reset functions when
their scripthost is cleared.
"Anon" referred to the fact that these proplists have neither a number,
like simple proplists, objects and effects, nor an ID like Definitions.
However, they now store the names of the global constant or property they
are in, so "Anon" is no longer appropriate.
There are now three classes of proplists:
- ordinary proplists (C4PropListScript) have a number only in the savegame
- objects and effects (C4PropListNumbered) always have a number
- proplists created during initialization (C4PropListStatic) have a path
So the function could be called NewNamed, but the source of the proplist
has been far more stable than the method used for serialization, and Static
somewhat describes the source.
C4Aul's Warn uses the format attribute to check for format string correctness.
Passing a dynamic string buffer from FormatString to it will break the build
with -Werror=format-string. Given that Warn already does the formatting itself,
just drop the use of FormatString
C4Set<T>::Sort() breaks the internals of the class which Guenther doesn't like. Now the sorted list is returned as a list of pointers into the original set.
Functions are refcounted now and might outlive their script. Fortunately,
the function destructor didn't really need the Owner. This further damages
the pretense of multiple scriptengines, but that could be repaired by
storing a pointer to the engine in the functions.
Mostly by changing functions to take a const reference, but also by using
move constructors. This helps with C4String leak debugging by reducing the
reference count changes.
Previously, only the outer proplist would be copied, but the parser expects
the inner proplists to also be present. Copy proplists deeply instead, as
is already done for functions, and in the linking step.
Since the script engine doesn't have an appropriate function to create the
proplist in, simply create it in the constructor and arrange for the
string table to be constructed first.
Because the interpreter throws for every function that is called with a
this parameter that has been removed, this() isn't a function anymore.
The function could stay around so that Call("this") or foo->this()
would still work, but I doubt any script ever did that.
These operators have a stricter definition of equality than the == and !=
operators. Those are already stricter than in some other languages, so the
new ones are probably not needed very often. But if the need does arise,
there's no workaround short of modifying the data structures and checking
whether they are still the same.
The rope will create a C4AulScript for the rope engine functions instead of
putting them into the global scope, and we might want to put C4Object-only
functions into a separate C4AulScript some day, too.
The map is currently only used in the parser for some warning heuristics.
Since it uses a hash table with separate chaining and the amount of
functions is fairly predictable, the hash table doesn't have to be
resizable.
The parser now copies the contents of the proplists in the order of their
source scripts into the final proplist. This way, local variable contents
get properly included, and the list of functions has one user less.
Also move C4AulDefFunc and C4ScriptFnDef to the same header the template
helper classes are in. Like them, these classes are a mostly invisible
implementation detail of the engine script functions.
The C4AulScriptContext is now an implementation detail of C4AulExec.
Also consolidate the C4Object * Obj and C4PropList * Def members to just
C4PropList * Obj and convert that to C4Object * on demand.
Constant expressions for global constants and for Definition properties are
now treated the same way. The preparser creates the structure that
the parser will fill in. Since the structure will not move, the parser can
refer to it before it is filled in, just like functions can call siblings
defined further down in the script. This will also allow proplists (and later
functions) to refer to each other.
For example, the proplist in Clonk.ActMap.Walk is saved as DClonk.ActMap.Walk.
Should the script defining the proplist change while the savegame is stored,
the proplist will have the new contents instead of the old ones after savegame
load.
Also, save functions as DFlint.Hit instead of fDFlint.Hit. Loading uses the same
code as static proplist loading.
Curiously, this makes g++ 4.4 use the C4RefCntPointer move constructor,
which was broken until now. Fix it to take a mutable rvalue reference.