5 ms·
Ummm, excuse me, but where the f&$k has this been hiding? I’ve been looking for ways to extend my go applications with scripting support. I started with Lua (wo
by gabereiser 3y ago
Ummm, excuse me, but where the f&$k has this been hiding? I’ve been looking for ways to extend my go applications with scripting support. I started with Lua (worked ) then Python (worked but hacky) then javascript using otto [1]. However it lacks ES6 support so having pretty OOP js code is a non-starter. I would love to have Java as a runtime that can be executed from goroutines.
[1] https://github.com/robertkrimen/otto https://github.com/robertkrimen/otto
- rainingmonkey 3y agoWhat was your experience with Lua if it worked? What were the disadvantages that kept you looking for other extension languages?
- gabereiser 3y agoAdvantages, Lua is old and simple so implementing it was a breeze. Disadvantage, I kept running into scenarios where oop made more sense and extending an interface. I could have done that through convention, but it’s not for me. I need to “enforce” the interface more than just a try catch. That led me to Python. Which also worked and suited that need for interface contracts but it introduced new problems. How can I enforce memory guards and sandboxing and execute parallel Python contexts? I ran into road blocks and gave Otto a try as it’s written in go, I would have more luck making the necessary changes if I needed a feature.
- donio 3y agoNot the parent but there are several high quality native (meaning no CGO) Lua implementations for Go and it's a great choice if you want an embedded scripting language: https://github.com/yuin/gopher-lua https://github.com/yuin/gopher-lua https://github.com/Shopify/go-lua https://github.com/Shopify/go-lua Unless you specifically need a JVM either of these will be a much more practical and mature choice for embedded scripting. Alternatively if you prefer JS then Otto is a good choice: https://github.com/robertkrimen/otto https://github.com/robertkrimen/otto
- gabereiser 3y agoI used Shopify's go-lua. It was the simplest to integrate. Otto is what I'm on now but with a "lot" of shims to get ES6 classes to work.
- sam_on_the_web 3y agoHave you had a look at Starlark? Its a python-like scripting language built specifically for embedding into applications. Originally it was written in Java to be used in Bazel but its been re-implemented in go and rust and has found use in a bunch of other places. https://github.com/google/starlark-go https://github.com/google/starlark-go
- gabereiser 3y agoYeah, it’s cool but doesn’t fit my use case. I’m not scripting configuration. I’m scripting functionality. I need to be able to enforce interfaces and signatures easily all while having near-go-like performance. I’ll play around with it some more and see if I can’t get some OOP pydantic-like stuff going with it. Otherwise it’s a non-starter.
- skitter 3y agoIf you want near-go-like performance, Jacobin doesn't help you either.
- gabereiser 3y agoI can handle <10 orders of magnitude performance loss, I can't handle 100+ as I get with Lua and other scripting engines in go.
- hinkley 3y agoWhat didn’t you like about Lua for your problem domain? It’s used quite a lot in computer games, and even nginx supports it.
- gabereiser 3y agoI’m familiar with it from my many years using it in game engines (and implementing it in them). My problem is it’s fluid by nature. The concern of validation and interface semantics are dependent on the implementation, rather than as an engine driving the process. I could expose some functions and write a bunch of docs on which ones to call first, or I could switch to a more OO approach. I chose the latter. If I want to script behavior, Lua is great. Python as well. But I’m not scripting behavior - I’m providing an engine.
- verdverm 3y agoCUE is another interesting language to use from within Go, and is rather natural, given CUE is implemented in Go, but you can also do way more cool things with CUE via the Go API. We're using CUE to validate and transform data, as input to code gen, the basis for a DAG task engine, and more https://cuelang.org https://cuelang.org | https://pkg.go.dev/cuelang.org/go@v0.6.0/cue https://pkg.go.dev/cuelang.org/go@v0.6.0/cue | https://cuetorials.com/go-api https://cuetorials.com/go-api (learn about CUE) https://github.com/hofstadter-io/hof https://github.com/hofstadter-io/hof (where we are doing these things)
- gabereiser 3y agoNot remotely close to my use case. Data filtering and extraction seems to be its niche, a problem you’re solving using it. My use case is different.
- verdverm 3y agoindeed, I've been looking for something more scripty to use from Go programs as well. Curious about the Gp+LUA, but haven't had the time to try it Generally, this subthread became several comments about using lang X in Go
- evacchi 3y agoI am a fan of the Jacobin project! For your uses, you may also want to consider wazero [1], a pure-go WebAssembly runtime. Full disclosure: I am on the team :) [1]: https://wazero.io/ https://wazero.io/
- gabereiser 3y agoI’m doing distributed backends, not webassembly, how does wazero fit into that scenario?
- evacchi 3y agoI don't know what kind of use case you have in mind specifically, but wherever you would use a scripting engine, you can embed a small Wasm runtime instead and let your end-users pick their favorite* language (*) as long as there is a toolchain that supports using it on Wasm :P
- sproketboy 3y ago[dead]
- alex0ptr 3y agoHave you considered just using go? https://github.com/traefik/yaegi https://github.com/traefik/yaegi