Cotton Scripting API

Cotton Scripting API

1.1k Downloads

Engine Wishlist

LemmaEOF opened this issue · 29 comments

commented

With stock Cotton Scripting, you can only really use JavaScript for scripting, and even then Nashorn is being deprecated. I want to see if we can get some JSR-223 engine addons to let people run other scripting languages. The primary ones we should get support for are:

  • Lua (multiple options: LuaJ, LuaJIT, JNLua)
  • Python (Jython for 2.7, but I can't find anything for 3.x)
  • SCarpet (could potentially run on top of Python?)
  • Ruby (JRuby)

If anyone knows good JSR-223 compliant engines for any of these languages that are under permissive license, please send them here.

commented

As discussed on discord, kotlin can be a good addition, as it's one of the few statically typed scripting languages.
Loading languages as addons could also be an option. If we know which ones are the ones that are actually used, than we can package those as defaults.

commented

I was primarily thinking the addons route since we can just nest addons once we're happy with them and give folks an option to only pack the addons they want.

commented

What I think would be easiest to implement is ZenScript. It is open-source, and was made for minecraft scripting.

commented

Is there a JSR-223 engine for ZS?

commented

No, there isn't. The problem with ZenScript is that it is very focused in on Minecrafting scripting and especially recipe tweaking, and so there's not really a general interpreter to run code that isn't related to Minecraft. It's not JSR-223 compliant, so it can't really be added.

commented

Not sure. It might not be too hard if it wasn't JSR-223.

commented

The system is designed to work with java script engines. Not being compliant, means that you can not reuse the same compat layers that we can use for every other language, and you have to re-implement every single thing ever added specifically for it, instead of working out of the box.

Zenscript did came up in my head as a good option for familiarity, but...

commented

For zenscript's functionality, you'd implement your api once in java, (code that works from java as well), than it works from javascript, kotlin, lua, python etc...

commented

Ultimately, it would likely require writing a new ZenScript interpreter from scratch that’s redesigned fundamentally to be a more abstract scripting language, and I don’t currently have time for that. I’d rather focus on making support for languages that already have compliant interpreters.

commented

scripting-cpython seems like it might work for a python scripting lib, but I don't know Maven and so I can't get it to compile. If someone could help get me a jar of it so I could shadow it, that'd be aces.

commented

…wait, I might be able to jitpack it.

commented

It looks messy.

commented

Yeah, it honestly does, but it's the only JSR223 python 3.x I can find.

commented

in fact, the only other JSR223 python I can find period is by the same group and it looks to be set up in nearly exactly the same way. edit: taking a more thorough look it looks a bit less messy, but I really wanna have python 3.x support instead of 2.7 so I don't know what to do

commented

Alright: new problem with the python JSR223 stuff is that it's made with maven, not Gradle. This is an issue because it means that I can't use shadow for them, which basically defeats the entire point. I'm not sure what to do. I'll ask some others if they have any ideas.

commented

Is it up on a branch?

commented

I've almost got it ready! It turns out Loom/Loader will let you JiJ any jar, not just a Fabric mod. That means I can just include the jar from maven and it'll be fine!

commented

https://github.com/CottonMC/cotton-scripting-py2/releases/tag/1.0.0 Jython version is now available. I'm gonna keep hunting and see if scripting-cpython is feasible to use for python 3.

commented

why

commented

A few updates, since it's been a while:

  • scripting-cpython is not feasible to use, since it depends on the python installed on the host computer, and it's difficult passing objects between JVM and Python VM.
  • I made an attempt to make a mod wrapper for Kotlin JSR-223, but without any luck due to weird classpath issues.
  • I started working on a mod wrapper for Frege, but I need to put stuff onto maven local for it to work properly.
  • Groovy has a Compilable and Invocable script engine, and Juuz is thinking of making a mod wrapper for it.
  • LuaJ has a Compilable script engine but not an Invocable one, which means that it can't 100% be used. I might try PR'ing in Invocable support someday.
commented

Frege? That's interesting.

commented

Frege has a Compilable but not Invocable script engine. That should theoretically be fixable too.

commented

@Frontrider Fabric Kotlin should absolutely not have the script engine already in here, because it would triple the size of the mod (because it'd need the entire kotlin compiler) and only LibCD and Cotton Scripting would use it.

commented

Frege would be an interesting one.

Fabric Kotlin should have the script engine already in there.

commented

Groovy has a Compilable and Invocable script engine, and Juuz is thinking of making a mod wrapper for it.

That wrapper is now done: https://github.com/CottonMC/CottonScripting-Groovy

commented

That was forgelin, yeah. This one does something else.

commented

now i'm beginning to miss this just looking at it

commented

now i'm beginning to miss this just looking at it

I might work on something like this in the future.

commented

I mean feel free to PR to this if you wanna extend it, I got myself burnt out on minecraft modding again (and I also wanted to try and make Chase which probably wouldn't work with Parchment at all oops)