Skip to content

Commit

Permalink
Added support for (fake) enums
Browse files Browse the repository at this point in the history
  • Loading branch information
YellowAfterlife committed Aug 13, 2024
1 parent 9296b55 commit 5749a31
Show file tree
Hide file tree
Showing 8 changed files with 406 additions and 144 deletions.
85 changes: 80 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,87 @@ The DLL does code preprocessing and other operations that were deemed too slow t

The scripts use `object_event_add` + `event_perform_object` to store and call the final code without parsing penalties that would occur with `execute_string`.

## Intended use cases
<p align="center">
## Syntactic sugar

<table><tr>
<th>Syntax</th>
<th>Result</th>
<th>Notes</th>
</tr>

<tr><td> <!-- row -->

```gml
var i = 0
globalvar g = 1
```

</td><td>

```gml
var i; i = 0
globalvar g; g = 1
```

![shrug](./misc/shrug.png)\
~~What use cases?~~
</td><td>

Single-variable declarations only!

</td></tr>

<tr><td> <!-- row -->

```gml
enum E {
A,
B,
C = 5,
D
}
trace(E.D);
```
</td><td>
```gml
global.__E__A = 0;
global.__E__B = 1;
global.__E__C = 5;
global.__E__D = 6;
trace(global.__E__D);
```

</td><td>

Init is done on spot - avoid function calls in enum field "values".

</td></tr>

<tr><td> <!-- row -->

```gml
missing(1, 2);
```
</td><td>
```gml
snippet_call("missing", 1, 2);
```

</td><td>

Allows snippets to call each other without forward declaration.

</td></tr>

</table>

## Intended use cases

</p>
| ![shrug](./misc/shrug.png) |
|:-:|
| ~~What use cases?~~ |

You could use it for dynamic content loading if you are making a game in GM8.1.

Expand All @@ -57,6 +131,7 @@ If you compile a [GMEdit](https://github.com/YellowAfterlife/GMEdit/) version fr
- Wildcard support in listfiles?\
(`folder/*.gml`)
- `script_execute` hook (that does either script_execute or snippet_call depending on whether index is number/string)
## Meta
Expand Down
3 changes: 3 additions & 0 deletions snippets/CharTools.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#pragma once

namespace CharTools {
inline bool isLineSpace(char c) {
return c == ' ' || c == '\t';
}
inline bool isSpace(char c) {
switch (c) {
case ' ': case '\t': case '\r': case '\n': return true;
Expand Down
4 changes: 3 additions & 1 deletion snippets/preBuild.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@echo off
goto bye
set dllPath=%~1
set solutionDir=%~2
set projectDir=%~3
Expand All @@ -16,4 +17,5 @@ if %ERRORLEVEL% EQU 0 (
--gml "%solutionDir%snippets_gml/snippets_discard.gml"^
--gmk "%solutionDir%snippets_gml/snippets_autogen.gml"^
%projectDir%snippets.cpp
)
)
:bye
Loading

0 comments on commit 5749a31

Please sign in to comment.