Commit Graph

874 Commits (master)

Author SHA1 Message Date
Lukas Werling ee0b1c2599 Implement JSON serialization for C4Value 2017-02-17 23:29:01 +01:00
Nicolas Hake 78bbbc917b Fallback to sane settings when compiling scripts without ScriptHost
Compilation without an associated ScriptHost happens in a call to eval,
in which case we'll fall back to the default warning settings (because
we don't have a location which we could get settings from).

Fixes #1891.
2017-02-16 19:32:42 +01:00
Nicolas Hake 1594acd3ed Aul: Warn if a function parameter shadows a local variable
Yeah. Aul looks up function parameters before local variables when
trying to resolve an identifier. Usually this doesn't matter, but you'll
notice it if you have a local variable and a parameter with the same
name, because the variable should be initialized to nil yet you get the
value of the parameter.
2017-02-13 17:20:03 +01:00
Nicolas Hake 2b5d34f420 Aul: Remove unnecessary virtual dtor from Script node
The dtor (which didn't even do anything) broke testing on g++ and clang,
because they correctly delete some ctors if the dtor is declared.
2017-02-13 15:23:51 +01:00
Nicolas Hake 30c5bb5f8d Aul: Allow the user to selectively enable/disable warnings
This commit introduces a new Aul directive "#warning", which can be used
to enable or disable warnings for a particular piece of code.

"#warning enable" enables all warnings.
"#warning disable" disables all warnings.
"#warning enable empty_parameter_in_call" selectively enables one
specific warning while not affecting any other.

All warnings that used to be controlled by Developer.ExtraWarnings
remain disabled by default.
2017-02-13 15:07:50 +01:00
Nicolas Hake 23bf3c4f0a Aul: Don't explicitly prepend "ERROR" to runtime errors
Since the error handler would itself prepend "ERROR", runtime errors
used to be written as "ERROR: ERROR: <whatever>".
2017-02-13 15:07:50 +01:00
Nicolas Hake a026bda561 Aul: Let error handler count warnings and prepend severity
Instead of explicitly writing to the log, let C4AulParse and
C4ScriptHost warnings go to the error handler to do with as it sees fit.
2017-02-13 15:07:50 +01:00
Nicolas Hake 5f520c6326 C4AulCompiler: Don't double-count compile time warnings 2017-02-13 15:07:50 +01:00
Nicolas Hake a33d98ee71 Aul: Warn on empty controlled statement
Aul will now emit a warning if you type something like
    if (...); return true;
(note the semicolon right after the condition). It will also warn on an
empty 'else' branch. If you actually intended to have a no-op there, use
an empty block '{}'.
2017-02-05 14:17:37 +01:00
Lukas Werling ef4f1d9231 Merge branch 'ipv6' 2017-01-18 21:59:16 +01:00
Lukas Werling b3ef196935 Remove ResolveAddress()
As setting a default port is a common operation, add a helper function
for this.
2017-01-18 21:54:50 +01:00
Nicolas Hake 102047f537 Implement IPv6 support to C4NetIO 2017-01-09 20:34:43 +01:00
Nicolas Hake b0b0533227 Make c4script binary use our private getopt library if necessary
Systems that don't come with getopt/getopt_long in their runtime library
need to link to our private copy; link that and use the right const-ness
for its prototype.
2017-01-07 13:41:45 +01:00
Nicolas Hake eeea131674 Aul: Enable better for loop generation
Instead of jumping forward and back repeatedly per iteration, we're
moving the incrementor past the body, which is when it's supposed to be
executed anyway.
2017-01-07 13:35:51 +01:00
Sven Eberhardt d46f98fd7b Add EditorCollection callback
To be used to re-route contents created/moved in editor.
2017-01-01 17:00:56 -05:00
Lukas Werling 52626fe021 Fix AulCompiler leaking C4Strings with variable names 2016-12-24 00:13:02 +01:00
Lukas Werling 61962fe70a Add --check/-c parameter to c4script for syntax checking 2016-12-23 17:18:00 +01:00
Nicolas Hake 60829ae5e4 Aul: Don't let exceptions escape from constant resolver
Letting the constant resolver throw exceptions prevented us from doing
checking on later initializers anyway, so instead we'll send them to the
error handler. As a special bonus this makes it so we don't crash when
a global variable initializer has errors. Fixes #1850, #1855.
2016-11-30 13:37:33 +01:00
Sven Eberhardt c5623aa7a2 Fix crash on script error in DirectExec scripts 2016-11-20 13:14:57 -05:00
Nicolas Hake 34bdab6ba5 Aul: Don't force assertions active
Assertions are great for debugging, but in public builds they just kill
apps dead.
2016-11-13 11:07:22 +01:00
Nicolas Hake eda6cc9c7f Aul: Gracefully handle errors in codegen (#1840)
By continuing to generate bytecode even after an error is found, we're
able to find more syntax errors and will also be able to keep the value
stack at the expected height.
2016-11-13 11:07:21 +01:00
Nicolas Hake ff0325dfac Aul: Always reset the current function when a declaration ends (#1839)
When an error occurred during codegen of a function, the current
function pointer would not be reset to 0, leading to spurious warnings
about redeclaration of functions.
2016-11-13 11:07:01 +01:00
Sven Eberhardt 072e1dcde0 Editor graph delegate: Add update callback functionality for graph edits 2016-11-12 22:20:05 -05:00
Sven Eberhardt 91af5a95be Editor graph delegate: Add HorizontalFix, VerticalFix and StructureFix constraints 2016-11-12 22:20:03 -05:00
Lukas Werling 6847e50e79 Implement setting shader uniforms from script (#1206)
Uniform variables are read from the "Uniforms" proplist set on Scenario
or on individual objects. Proplist keys are uniform names. Values can
either be an int or an array of one to four ints in C4Script. In GLSL,
the uniforms then need a matching type (int/ivec2/ivec3/ivec4). There is
no error reporting; uniforms are only set if both name and type match.

The implementation walks the "Uniforms" proplists on each Draw call. We
may need to cache the uniform maps if this turns out to be too slow.
2016-11-12 22:09:23 +01:00
Sven Eberhardt bf9c940aa6 Editor graph delegate: Add edge and vertex properties. Remove graph storage options.
The different storage options weren't really needed and would not work with edge and vertex delegates.
2016-11-10 21:43:43 -05:00
Sven Eberhardt 1e52ed5a74 Remove unused variable ndx in C4AulParse::Parse_Expression 2016-11-10 21:43:41 -05:00
Sven Eberhardt ebda8193ef Replace NULL by nullptr in C++ sources
We don't support pre-C++0x any more, so nullptr should be fine everywhere (except in the plain C source files)
2016-11-02 19:58:02 -04:00
Sven Eberhardt 54e8c14666 Editor: Add graph, polyline and polygon shape delegates 2016-11-02 09:54:31 -04:00
Lukas Werling 9c98227a03 Fix all -Wformat warnings 2016-10-31 23:39:45 +01:00
Nicolas Hake 194e7d709b Aul codegen: Handle errors at codegen time better (#1837)
If a parse error occurs inside a declaration, the codegen should just go
on and deal with the next declaration instead of completely giving up on
the entire script.
2016-10-31 11:17:43 +01:00
Nicolas Hake f0f50ec402 Aul: Don't prepend "ERROR:" to parser error msgs
Further formatting of the error message should be the error handler's
job.
2016-10-31 11:16:14 +01:00
Nicolas Hake 3c13c88f56 Aul: Count errors and warnings properly
9caaf1e introduced an external error handler for easier testing of
error conditions. The default error handler needs to count errors and
warnings if we want to display them, but didn't.
2016-10-31 11:15:19 +01:00
Sven Eberhardt f2231e848e AulCompiler: Fix static parameter type check 2016-10-24 22:00:30 -04:00
Julius Michaelis 376ca5a9df Prevent using USE_CONSOLE in lib{misc,c4script} 2016-10-22 17:42:23 +02:00
Nicolas Hake cada67c097 Prohibit overriding local vars with functions (#1831)
The old parser threw a standard compile error in this case; the
AST-based parser threw an ICE, which is ultimately the same thing but
made it sound like the parser was at fault. And maybe it is, and we
should allow code like "local a; func a() {}" but that seems like it
should be a conscious design decision.
2016-10-21 22:32:24 +02:00
Julius Michaelis 34a9a1de8d Twiddle with header organization: lib{misc,c4script} do no longer include GL/glew.h
(Yes, it is just that complicated.)
2016-10-20 18:46:32 +02:00
Nicolas Hake e2fd7095c1 Merge branch 'ast'
# Conflicts:
#	src/C4Include.h
#	src/script/C4AulCompiler.cpp
#	src/script/C4AulParse.cpp
#	src/script/C4AulParse.h
#	src/script/C4ScriptHost.cpp
#	src/script/C4ScriptHost.h
#	tests/CMakeLists.txt
2016-10-20 17:33:02 +02:00
Nicolas Hake 266feeda4d Aul: Add AST generation tests
Just making sure the parser creates the AST the way we expect before we
hand off the code to the codegen.
2016-10-20 17:20:55 +02:00
Nicolas Hake 118961d0b7 Aul: fix octal escape parsing
Bet you didn't know C4Script supported octal escapes inside strings.
Well, it didn't; or at least not correctly.
2016-10-20 16:53:23 +02:00
Nicolas Hake 5915f79960 Don't entirely recreate global vars in second compile pass
This allows people to properly cross-reference two proplists from each
proplist's initializer.
2016-10-19 14:20:48 +02:00
Nicolas Hake 021a6e89f5 Implement direct execution of whole function definitions
This implements the changes made in c6e4bfd on the AST-based parser.
2016-10-19 14:20:47 +02:00
Nicolas Hake 1a8db9e109 Make C4ScriptHost store C4Value refs to owned functions
C4Value already handles refcounting properly for us, so we don't need to
do it manually. It might still be worth manually refcounting them
to avoid the boxing/unboxing overhead, but it's only needed at load and
unload so it's not a priority at the moment.
2016-10-19 14:20:46 +02:00
Nicolas Hake 5f3dbdd417 Reject function expressions inside proplists inside functions
These aren't supported by the codegen on account of not working in
savegames.
2016-10-19 14:20:45 +02:00
Nicolas Hake 9caaf1e298 Aul: Split out error handling into a separate class for easier testing
By using an extern error handler in the script engine, we can mock that
handler and make sure something that should fail actually does, instead
of having to parse log messages.
2016-10-19 14:20:41 +02:00
Nicolas Hake f7a04624eb Remove references to functions defined in unloading defs (#1776) 2016-10-19 13:45:59 +02:00
Nicolas Hake ab1e6bd5a4 Allow proplist-local funcs to access vars of their owner's prototype
Thanks to JCaesar for providing this test case.
2016-10-19 13:45:35 +02:00
Nicolas Hake 1b32633806 Add C4LangStringTable::system_string_table def'n to standalone stubs 2016-10-16 20:11:13 +02:00
Sven Eberhardt 06a438e05e Editor object list: Remove effects; add Global and Scenario 2016-10-15 10:06:44 -04:00
Nicolas Hake 66d5ef8b08 Reset codegen target after parsing nested function
Parsing a function expression inside another function failed to reset
the code generator target to the containing function, so all following
bytecode would still be appended to the nested function, leaving the
container broken.
2016-10-12 14:56:54 +02:00
Armin Burgmeier 836927d93c Don't leak static proplists with cyclic references
If a local variable in a definition was set to a proplist inside the
Definition() callback, and that proplist contained cyclic references
then those references were leaked. Typically cyclic references for
script-created proplists are broken in
C4PropListScript::ClearScriptPropLists, however definition proplists
are changed to be static proplists in
C4PropList::FreezeAndMakeStaticRecursively.

To fix this, each script host maintains a list of proplists made static
by FreezeAndMakeStaticRecursively, and explicitly deletes all of these
proplists on Clear().

This leak also leads to an assertion failure inside
C4PropListScript::ClearScriptPropLists in debug mode, and can also be
observed by C4PropList::PropLists not being empty after game clear.

The definition in Objects.ocd/Helpers.ocd/UserAction.ocd constructs
cyclic proplists in its Definition() call. A simpler, more minimal way
to provoke the leak is the following (it provokes the leak but not the
assertion failure):

    local bla;

    func Definition(def)
    {
        bla = {};
        bla.test = { Name="Test222" , Options = { Name="Test333" } };
        bla.test.Options.Link = { Name="Test444", Blub=bla.test };
    }
2016-09-30 17:50:41 -10:00
Lukas Werling 8a09fcc1b1 Increase REPL output depth to 10 (from 1)
This makes working with nested arrays and proplists a lot less annoying.
2016-09-26 16:33:24 +02:00
Lukas Werling 880981ad31 Fix build on systems with non-long regex index types 2016-09-18 19:40:32 +02:00
Lukas Werling fbb8ad5d87 Add RegexSplit() 2016-09-18 11:10:19 +02:00
Lukas Werling 219f81f004 Regex: Fix off-by-one error 2016-09-18 10:49:06 +02:00
Lukas Werling 619ad27a91 Regex: Fix infinite loop with zero-length matches 2016-09-18 01:16:06 +02:00
Lukas Werling d7cd224a4f Add functions RegexReplace, RegexSearch and RegexMatch 2016-09-16 23:46:03 +02:00
Sven Eberhardt 2c20204021 Add C4SECT_ReinitScenario flag for LoadScenarioSection
This also resets the script engine and does player init callbacks. Useful to restart the scenario in the editor.
2016-09-07 01:53:53 -04:00
Sven Eberhardt 5523e685fb Fix script engine assertion on game clear 2016-09-06 01:13:53 -04:00
Sven Eberhardt dee6086e1d Fix access violation in proplist-to-static conversion 2016-09-06 01:09:29 -04:00
Sven Eberhardt 31121d682c Rename option default value function property to DefaultValueFunction
It was "Get" and later "Set", which was always a bit confusing.
2016-09-01 18:32:24 -04:00
Sven Eberhardt 6b9df3118c Sort UserAction evaluators and groups by name
Also merge effect group into ambience group.
2016-08-27 16:46:59 -04:00
Sven Eberhardt e4b4246500 Fix freezing and assignment of static names to child proplists created in Definition()-callbacks (#1798)
Also adjust editor props for the change:
1. enum needs to create a copy, not a reference for the default value of an option if it is defined inline
2. Always use proper GetName() resolution on property group names even if a static name would be available
2016-08-27 02:04:03 -04:00
Sven Eberhardt 5d6ecc8dc8 Fix possible hang on effect execution with timer=1
If a timer=1-effect registered another timer=1-effect into the same object, it could cause an endless loop. This happened if the timer in the sequence object was set to 1.
2016-08-18 00:14:19 -04:00
Sven Eberhardt 4581022411 Fix an aul preparser crash on DirectExec functions parsing
GetLastRetType doesn't work because the preparser does not generate code.

The code looks a bit like this line just got lost somehow?
2016-08-08 15:26:25 -04:00
Sven Eberhardt fc24969899 Add EditorPlacementLimit property
Limits the number of object instances that can be placed of a given def.
2016-08-06 02:36:53 -04:00
Sven Eberhardt bce09d272d Add EditorInitialize callback 2016-08-04 22:12:10 -04:00
Sven Eberhardt 24a5dc33db Qt editor: Sort properties in property list by localized name and priority 2016-08-02 01:12:08 -04:00
Sven Eberhardt b1a1df8dee Add eval parameter to not pass errors 2016-07-31 08:15:54 -04:00
Sven Eberhardt 18444c7e0d Add StringToIdentifier script function
Required to sanitize variables in the editor. Works by stripping all non-identifier characters and preprending a _ if necessery.
2016-07-30 21:43:01 -04:00
Sven Eberhardt 442b8e66df Qt Editor: Add short name for enum delegate options displayed as sub-delegate 2016-07-30 14:50:07 -04:00
Sven Eberhardt 37885a2e4f Qt Editor: Add AllowEditing flag for enum delegates.
Used for sound delegate
2016-07-28 00:24:28 -04:00
Sven Eberhardt ee88a36f73 Qt Editor: Rename EditorInfo to EditorHelp
Fits better with "UsageHelp" and is more precise.
2016-07-24 23:10:43 -04:00
Sven Eberhardt 534e4cc745 Merge branch 'master' into qteditor
Conflicts:
	src/script/C4AulParse.cpp
2016-07-24 10:23:57 -04:00
Sven Eberhardt 4245f60e83 Qt Editor: Add help/description label for current selection 2016-07-24 10:12:38 -04:00
Sven Eberhardt 14d01cd5cd Qt Editor: Add EmptyName option for def property to rename the "nil" entry 2016-07-22 00:28:01 -04:00
Sven Eberhardt 4fad947980 Qt Editor: Add Set function options SetGlobal and SetRoot 2016-07-21 00:24:53 -04:00
Sven Eberhardt d605bab0be Qt Editor: Move EditorActions from EditorAction_* to a proplist EditorAction.* 2016-07-14 00:17:53 -04:00
Sven Eberhardt 28d2172b78 Qt Editor: Move editor props from EditorProp_* to an EditorProp proplist 2016-07-13 17:18:08 -04:00
Sven Eberhardt d9f31b006b Add ReplaceString script function 2016-07-13 02:12:31 -04:00
Lukas Werling 2127e78db1 Fix c4script build 2016-07-07 22:50:13 +02:00
Lukas Werling 791315a54e Fix #include-in-#appendto, but discourage with a warning 2016-07-07 21:13:18 +02:00
Nicolas Hake dcd8d9676a Fix unloading scenarios with Map.c or System.ocg scripts (#1778)
Destruction order matters!
2016-07-07 14:39:18 +02:00
Nicolas Hake 4725043493 Def unload: Fix overloaded function refcount 2016-07-07 14:34:24 +02:00
Sven Eberhardt 85c5deb099 Qt Editor: Add option to auto-select objects created by an EditorAction
To be used by the dialogue so you can press a button on the clonk to add and immediately configure a dialogue.
2016-07-07 01:36:58 -04:00
Nicolas Hake 7ff8c4f95a Remove references to functions defined in unloading defs (#1776) 2016-07-06 14:41:22 +02:00
Sven Eberhardt 990b6ea8f1 Qt Editor: Add option to descend directly into a subpath from array and sequence property delegates 2016-07-06 00:56:08 -04:00
Sven Eberhardt 62c1f4bda5 Qt Editor: Add callback support for dynamic enum values in Enum delegates 2016-07-04 13:21:30 -04:00
Sven Eberhardt b34ae09437 Fix utility builds 2016-06-21 21:48:10 -04:00
Sven Eberhardt a7aa89f168 Merge branch 'master' into qteditor
Conflicts:
	planet/Objects.ocd/Structures.ocd/StoneDoor.ocd/SpinWheel.ocd/Script.c
	src/platform/C4WindowSDL.cpp
	src/script/C4AulParse.cpp
	src/script/C4Effect.cpp
2016-06-20 22:27:03 -04:00
Sven Eberhardt 068004d9af Remove unused variable in C4AulExec 2016-06-20 15:50:36 -04:00
Sven Eberhardt c6e4bfd585 Aul: Add DirectExec method for executing a complete function definition. 2016-06-20 01:37:04 -04:00
Sven Eberhardt 34289fa18a Qt Editor: Add EditorActions.
Replacing the old EditCursorCommands (which nobody knew). Objects now publish their commands directly on the property viewer.
2016-06-19 00:08:09 -04:00
Sven Eberhardt a7bd20a927 Fix server and utility build
Adding missing C4DefList::SortByPriority() stub
2016-06-18 10:35:54 -04:00
Sven Eberhardt ad863836b3 Qt Editor: Add groups to enum 2016-06-15 00:15:47 -04:00
Sven Eberhardt 397dbd867a Add DefinitionPriority property to control call order of Definition()-callbacks. 2016-06-07 18:22:43 -04:00
Sven Eberhardt 16e31098b4 Qt Editor: Improve proplist and array display/editing
* Add/Remove element buttons
* Display customization of user delegates
2016-06-06 01:54:05 -04:00
Sven Eberhardt 4d04135cda Fix GetPropertyBool default value when descending into prototype [Guenther] 2016-06-03 20:17:20 -04:00
Sven Eberhardt b10da0629d Qt Editor: More EditorProps types (string, array) and attributes (EditOnSelection, DefaultEditorProp) 2016-06-03 01:20:43 -04:00
Günther Brammer 57a35bf01b Don't crash on functions declared inside other functions
Declaring a local variable inside any function works the same way as
declaring it in top-level scope, which gets a bit weird if done inside a
function inside a constant proplist, but is at least consistent.

Thanks to Flinti for reporting this.
2016-05-25 01:06:10 +02:00