Skip to content

Add REPL (scripting) to devtools#86

Merged
elgopher merged 2 commits intomasterfrom
add-scripting
Aug 12, 2023
Merged

Add REPL (scripting) to devtools#86
elgopher merged 2 commits intomasterfrom
add-scripting

Conversation

@elgopher
Copy link
Owner

@elgopher elgopher commented Aug 5, 2023

This PR adds the ability to run Go code when the game is running. No need to compile, and restart the game. Just write the code in terminal, hit enter, and it will be immediately executed.

Go code is interpreted by traefik/yaegi interpreter. It is a Go interpreter compatible with standard Go compiler.

Lines are read from terminal by peterh/liner package. For now I'm using my fork of github.com/peterh/liner, because the original does not work well in Goland/VSCode on Win11 (see peterh/liner#163). This is temporary, until peterh/liner is fixed properly.

Limitations:

  • MidInt, MaxInt, MinInt - those functions can be executed in terminal but only accepts int's (not int64, byte etc.)
  • pi.Int cannot be used
  • The size of compiled game with devtools is increased by 3.7MB (+35% increase), the compilation takes 21% more time. But it is worth it. I plan to add a possibility to disable scripting in the future though.

@elgopher elgopher force-pushed the add-scripting branch 29 times, most recently from e3fa2f5 to c931993 Compare August 6, 2023 18:00
@elgopher elgopher changed the title Add scripting [PoC] Add scripting to devtools Aug 6, 2023
@elgopher elgopher force-pushed the add-scripting branch 26 times, most recently from 33472a9 to f55ebc5 Compare August 12, 2023 13:14
@elgopher elgopher changed the title [PoC] Add scripting to devtools Add scripting to devtools Aug 12, 2023
This commit adds the ability to run Go code when the game is running. No need to compile, and restart the game. Just write the code in terminal, hit enter, and it will be immediately executed.

Go code is interpreted by traefik/yaegi interpreter. It is a Go interpreter compatible with standard Go compiler.

Lines are read from terminal by peterh/liner package. For now I'm using my fork of github.com/peterh/liner, because the original does not work well in Goland/VSCode on Win11 (see peterh/liner#163). This is temporary, until peterh/liner is fixed properly.

Limitations:
* MidInt, MaxInt, MinInt - those functions can be executed in terminal but only accepts int's (not int64, byte etc.)
* pi.Int cannot be used
* The size of compiled game with devtools is increased by 3.7MB (+35% increase), the compilation takes 21% more time. But it is worth it. I plan to add a possibility to disable scripting in the future though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant