Package: gdrepl
GDScript REPLThis repo contains:A proof of concept gdscript REPLA dockerfile to build godot server for alpineA dockerfile to run godot from alpineA IRC gdscript REPL botNotice that if all you want is run gdscript files from the command line you don't need this project. Check out:https://docs.godotengine.org/en/stable/tutorials/editor/command_line_tutorial.htmlTable of ContentsMotivationInstallationUsageDevelopmentCLIServerEnvirontment variablesWhy the weird approachRun the IRC botDockerBuild GODOTBuild and image for the irc botWhy the dockerfile doesn't download godot binary automatically?TODOMotivationGdscript is a python like language but it lacks a reply. Godot has a built ingodot -s script.gdto run scripts but it is overkill when you just want to test out the difference between aPoolStringArrayand a normalArrayof strings and play around like you can do with so many languages.That inspired me to try to turngodot -sinto a repl, creating awebsocket serverthat will take any string from any client in, evaluate it by creating newGDScript, attaching that script to a resource node and then calling a function of that node. That requires a lot of hacky string manipulations to keep stuff working and have a separated local and global scopes allowing you to create functions, enums and classes from the repl.This is this still very work in progress and experimental but serves to prove the point that a repl for godot would be awesome.InstallationSimply:pip3installgdrepl

gdreplIf you want to use the irc bot you will need to clone this repos and follow the instructions for the bot bellow.UsageThe gdscript server is implemented in a way that it will send the return output to the client but not stdout. So if you type1+1you will receive2but you can't receiveprint(2)event though that will be still shown on the server's output.Currently this doesn't perfectly support multiline and you have to manually fix the identation sometimes. You can also "fake" multiline input in a single line in both the irc bot and REPL by using a;. Those will be replaced to\nat runtime, for example:funcinc(value):;varnew=value+1;returnvalueIt supports godot 3 and 4. If you dont have godot on your path use the--godotparameter to pass it or--commandto completely change the godot command, like if you dont want it headless, and in that case you have to manually specify-s path/sto/gdserver.gd. Example:gdrepl--godot/home/user/programs/godot/godotIf you are having problems try running the server and client separately. In one terminal run:gdreplserver--verbose# You can also pass --godot or --commandIn another one:gdreplclient# maybe --port NNotice that multiple clients can be connected to the same server.For more information checkgdrepl --help,gdrepl server --helpetc.DevelopmentCLIRequires python3Install godot headless. Ubuntu hassudo apt install godot3-serverwhich is very suitable for this. In another distros without that the script will fallback togodot --no-windowto run it headlessly.You can create a virtual environment or not:pip3 install requirements.pyRunpython -m gdreplWith this you will see both stdout and return output in the same window.ServerStart the server with:gdreplserver$python-mgdrepl--help
WelcometoGDScriptREPL.HitCtrl+Ctoexit.Ifyoustarthavingerrorstype'clear'Usage:python-mgdrepl[OPTIONS]COMMAND[ARGS]...

Options:--helpShowthismessageandexit.

Commands:repl*LaunchthegodotserverandstarttehreplclientConnectstoarunninggodotreplserverserverStartsthegdscriptreplwebsocketserverAlternatively you can directly run the godot script:godot3-server--scriptgdserver.gd# orgodot--no-window--scriptgdserver.gdYou can connect to this server using any websocket client. I recommendwebsocat:websocatws://127.0.0.1:9080# Or if you have rlwrap installed (You should)rlwrapwebsocatws://127.0.0.1:9080The problem with this is that stdout and stderr will be displayed on the server while only the return will be shown on the client.To connect to the server you can run:gdrepl client. You can then typehelpto see what special server commands you can run likescript_codeto check what currently generated script is.Custom server commands are:{"reset":"clears the script buffer for the current session","script_local":"Sends back the generated local","script_global":"Sends back the generated global","script_code":"Sends back the generated full runtime script code","dellast_local":"Deletes last local scope or code block","delline_local":"Deletes certain line number from the local script","delline_global":"Deletes certain line number from the global script","delglobal":"Deletes the entire global scope","dellocal":"Deletes the entire local scope","quit":"stops this server",}Environtment variablesIfDEBUG=1is set then the server will keep writing the formed script to stdout.IfTEST=1the websocket serevr wont run and simple test functions will be executed.Why the weird approachMy main goal was to make a safe to host irc bot repl, spawning a docker image for each command. TheOSmodule contains dangerous functions that allow you to run shell commands. In that process I realized it would be easy to make a normal CLI repl as well.Run the IRC botRequires python3 and a godot image. Use theirc_botfolder.Install gdrepl:pip3 install gdreplBuild a docker image for it (See section bellow).Copyconfig.py.exampletoconfig.pyEdit it for your needs.You can create a virtual environment or not:pip3 install bot/requirements.pyRun./bot.pyTo keep it running and manage it i recommend pm2:https://pm2.keymetrics.io/DockerBuild GODOTTo build godot for your platform rundocker-compose buildinside thebuild/directory. Then run./copy.shand the resulting binary will be insidebuild/bin/.This was only tested on AARCH64. If you want to run the irc bot in a supported platform simply grab godot-server fromhttps://godotengine.org/download/serverBuild and image for the irc botIf you build godot, put the binary inside thedockerfolder and rename it togodot. Then insidedocker/rundocker-compose buildand you will have it. You can also use the same docker image you build it from, just update the bot config accordingly.Why the dockerfile doesn't download godot binary automatically?Because I hate when I try to use one of those docker images but they are x86_64 only. Godot is fairly easy to build.
If you are on aarch64 like me (Raspberry Pi 4, oracle Ampere A1) this is how I build godot:sconsarch=arm64platform=servertarget=release_debuguse_llvm=nocolored=yespulseaudio=noCFLAGS="$CFLAGS-fPIC -Wl,-z,relro,-z,now"CXXFLAGS="$CXXFLAGS-fPIC -Wl,-z,relro,-z,now"LINKFLAGS="$LDFLAGS"-j4
stripbin/godot*TODOHave the gdscript websocket server be a proper api or protoccol using json or something less hacky than we have nowGdscript methods and properties auto completion using godot lspAuto unindent (like with else, elif)