Have you ever wanted to submit a MiniScript entry for the Micro Jam while still staying on your favourite game engine, have an easy to use alternative to Lua for modding your games or just have a lightweight yet fast embedded interpreter in your Godot project? Then this is what you're looking for!
Godot-X-MiniScript2 (AKA GDXMS2) is a set of bindings that integrate both the C++ and C# versions of the new MiniScript2 interpreter inside Godot 4's ecosystem—respectively using GDExtension(godot-cpp) and GodotSharp(Godot Mono).
Status:
This project is currently in its very early stages, albeit usable if you build the latest commit or use the latest release.
Description:
This project implements has 2 implementations in C++ and C# for wrapping MiniScript inside Godot4 specifically GDScript for quick iteration, particularly for the Micro Jam game jam in order to make MiniScript entries using Godot.
Currently the C# implementation is not done. But the C++ one has working basics which includes an Interpreter class with the methods create(source_code: string) (creates an interpreter instance, .new() not recommended), reset(source_code: string) to change its source code, compile() to compile the source code and run_until_done(time_limit: float, return_early: bool) to run the compiled code. More features are planned to be added and are WIP.
Check out the GitHub repository
Usage (in GDScript): an iterative factorial example
##example node script using the "Interpreter" class
extends Node
@export var test_number : int
func _ready() -> void:
#Init all global MiniScript components(GC, constants, error types, ...) and set the stdout and stderr
#In this case, they are the default godot stdout(print and push_error); but any method that takes a string will work
Interpreter.init_miniscript(print, push_error)
#create an interpreter object with its initial code set to the desired source code(to avoid resetting the interpreter after creation)
var interp = Interpreter.create(
#here we forcibly injected the variable in the source code since we don't have an I/O or value sharing API yet
"test_number="+str(test_number)+
"""
factorial=function(x)
if x==0 or x==1 or x==null then return 1
mult=1
for i in range(x, 2)
mult*=i
end for
return mult
end function
print factorial(test_number)
""")
#compile the interpreter's source code
interp.compile()
#run it with a 2-second time limit and with early returns (read MiniScript docs for more details)
interp.run_until_done(2.0, true)
Top comments (2)
This looks like a great start! People could build on this to do all sorts of things, from scripting the enemy AI, to making programming games, to exposing large parts of the Godot API and building your game mostly in MiniScript!
I'm also excited and thankful that you based this on MiniScript 2, which is nearly ready for official release — what it needs more than anything else is testing by people who aren't me!
Glad you liked it! MiniScript2 was the only way to get this working on web, because of MS1's poor error handling. I want to make sure this can work in web so that people can use this for the micro jam. I will definitely keep you up to date with further updates! 😁