9 ms·
Golua – A Lua 5.3 engine implemented in Go
- znpy 8y agoI see that contribution is guarded by CLA agreement. I often wonder: if I don't want to sign a CLA, couldn't I just fork the whole repository and keep going on my own?
- colonelxc 8y agoYes you can. The restriction is on what can be put into this "upstream" version.
- bhengaij 8y agoI don't want to be "that guy" but I think its a valid question to ask- why didn't they write this in ... ... .... Rust? I think go and rust serve two somewhat different use cases- go being for distributed computing in a nutshell, and rust for fast running programs. And I think Rust would have been a better choice Edit: looks like everybody and their dog has a Lua engine now- maybe I'll create one in rust
- 4ad 8y ago> why didn't they write this in ... ... .... Rust? Probably because they wanted to use it from Go?
- nine_k 8y agoLikely they wanted an idiomatic Go API, and maybe had more in-house Go knowledge than Rust knowledge. I can imagine how exposing a Rust API to a non-Rust program could be as problematic as a C++ API: your common denominator is a C API, which adds cumbersomeness and removes (some of) the safety.
- infogulch 8y agoOne of the motivations (linked in another comment) may reveal why: > We also wanted clean and idiomatic Go APIs If you want to use this as a scripting/plugin language for Go programs (say, for those distributed computing programs you mentioned), it's pretty defensible to make it integrate with Go better by... building it in Go.
- kryptiskt 8y agoThere is quite a big overhead calling out from Go, so folding stuff they want to use into pure Go often makes sense from a performance perspective.
- deleted 8y ago[deleted]
- arghwhat 8y ago> I don't want to be "that guy" Then don't.
- deleted 8y ago[deleted]
- SamWhited 8y agoThe more interesting question is "why Lua?" The issue others have linked says "We need a Lua 5.3 engine", I'd be curious why. Presumably that means they want to use some existing Lua plugins? Is this something that's built into Azure?
- Kubuxu 8y agoAnother reason might be GC. They are probably using Go's GC for Lua. In Rust you would have to also write the GC.
- deleted 8y ago[deleted]
- stcredzero 8y agoThey are probably using Go's GC for Lua. That's quick and dirty. Dirty, because the way Go's GC is optimized is likely to be very unsuitable for Lua.
- krylon 8y agoI am by no means an expert on that particular subject, but from what little I do know, both Go and Lua (the regular C version) have garbage collectors optimized for low latency; I may be wrong, but if I am not, it looks like a good match, doesn't it?
- zkomp 8y agoYeah but can't we have both? If you already have projects in go then a rust project will not be of any use, and vice versa...
- kibwen 8y agoIdiomatic Go code tries to use cgo sparingly, if at all. And the Lua embedding API makes calls into C with a very high frequency. I haven't tried, but I suspect that the combination of these two factors would make embedding a Lua engine written in C (or, say, in Rust with a C ABI) into a Go program disastrous for the performance of Go's green threading runtime. Alternatively, while it would be nice to have a Lua engine entirely in Rust, Rust goes to great lengths to make calling into C have no runtime cost, so you generally just see people writing Rust wrappers over the C API, which tend to impose varying degrees of additional safety on top (Lua internally does a ton of setjmp/longjmp, among other things, so it's not easy). A good example of "wrap and add safety" is Chucklefish's wrapper, being used for their game Witchbrook: https://github.com/kyren/rlua https://github.com/kyren/rlua
- zzzcpan 8y agoI think you got it backwards. Go is good for toy-interpreters, compilers, programming languages in general. Pretty bad for distributed computing though, Rust is definitely better for that use case if your only choices are Rust and Go.
- pjmlp 8y agoAs someone that is usually critic of some Go design decisions I fail to see why. If you are going to say GC, it all comes down to how one designs the respective data structures.
- monocasa 8y agoRust's type system is derived from the ML variants, and as such is fantastic for writing compilers and interpreters. ML stands for "meta language", ie. it's named after how good it is at writing compilers in.
- pjmlp 8y agoKind of, I prefer the productivity I get from the GC in ML language variants. Having done some compiler related work back when we had Caml Light, OCaml was still called Objective Caml and Mirada was being turned into Haskell, I don't see what I would gain from having to deal with the borrow checker.
- mfer 8y agoThe why not Rust is a valid question. It's because this was put together with an intent of being embedded in an application written in Go (https://helm.sh https://helm.sh). I'm a Helm maintainer so I'm familiar with the history of how this came to be.
- szemet 8y agoWhat is the advantage of using a full blown language for Helm configuration instead just using something, which is a bit more flexible, but not Turing complete like: https://github.com/dhall-lang/dhall-lang https://github.com/dhall-lang/dhall-lang (Or something similar) As Helm so far could operate with a simple template language , and now suddenly jumps to a Turing-complete configuration language - this seems quite large step... What is the justification?
- mfer 8y agoGood question. For 90+% of things a simple template languages works. But, there are cases where you need something more. For example, the features that were baked into Helm v2 to support installing OpenStack in Kubernetes were complex. IIRC, no one on GitHub has used these but they are complicated and in use privately. That complexity should be pushed to the chart rather than Helm. Helm shouldn't need to hold that complexity, which is in the direct line for everyone, for those complicated apps. This is where Lua comes in. Lua provides the ability to have the language embedded easily (it was designed for that) for use in cross platform situations (Windows included). Does that help?
- drej 8y agoIn case you are wondering why this exists, there is a discussion here: https://github.com/Azure/golua/issues/36 https://github.com/Azure/golua/issues/36
- wahern 8y ago> The VM is designed differently (I'm encouraging Brian to write a blog post about this), but in a nutshell it is designed for better error handling and for adding a debugger Looking at the VM, they implement function calls by recursively re-entering the VM in Go. The VM implements neither tail calls nor coroutines, and I don't see how they could implement the latter without some serious refactoring. Perhaps by adding a debugger they mean they implemented the VM such that they could repurpose existing Go debuggers, which is why there's a 1:1 mapping between the Lua call chain and the Go runtime call chain.
- mfer 8y agoThis was open sourced very early. It is being built with the intent of supporting Helm v3 and by open sourcing it early it enables other Helm maintainers to get involved and to import it into Helm v3 early. I expect more docs, details, and improvements will be coming
- wereHamster 8y agoYou mean this helm: https://helm.sh https://helm.sh?
- stcredzero 8y agoin a nutshell it is designed for better error handling and for adding a debugger Better debugging is one of the big things holding Lua back, IMHO.
- nikki93 8y agoI feel like the main thing to work on here is the frontend, given the "debug." library built into Lua(JIT). ZeroBrane has a frontend, for example.
- rcarmo 8y agoThis is great, since I've been meaning to do some stuff in Lua instead of JavaScript (mostly Functions-like stuff that require simple scripting). Having more options is always nice.
- swah 8y agoThere are a couple other Lua implementations in Go that exist for a few years though...
- Rapzid 8y agoI wonder what sort of VM monitoring will be available. Something that was interesting with HekaD's lua integration was the ability to monitor CPU usage and evict bad actors. Can it see and perhaps even limit? This was something I was wondering about with Cloudflares isolate implementation as well. I read that in node/v8 you can inspect an isolates CPU usage, but no way to limit it apparently? If you start out with 1/2 of a CPU but your program gets squeezed down to 1/1000 as more isolates are added or existing isolates use more time you could be in for a big surprise as your program no longer performs adequately, perhaps to the point of not functioning properly at all.
- mrkurt 8y agoIsolates are limited to a single thread. There's no built in way to throttle an isolate's CPU usage, but you can manage the thread it belongs to. Which means isolates aren't inherently worse for CPU contention than processes would be, you just need to roll your own throttling instead of using something like cgroups.
- le-mark 8y agoPeople always over look this, but it's critical to getting to a truly fair-use shared platform. You can do it with PUC lua using debug hooks. Not other runtime I know of has this feature.
- deleted 8y ago[deleted]
- azinman2 8y agoAmazing. Microsoft releases an open source implementation of a Lua VM written in Go. I feel like I’m in the twilight zone!
- pjmlp 8y agoMicrosoft is also responsible for Go's support on VSCode. And they just released an Azure Go SDK earlier this year.
- setquk 8y agoTentacles everywhere.
- delusional 8y agoBoth of which make sense, as they're integrations to other Microsoft owned and operated platforms. How go and lua fit into their product line I'm less sure of.
- sephware 8y agoNothing necessarily surprising about this. Yes Go is made by Google, but not by all of Google, just like this project isn't necessarily a first-class Microsoft project (although it might be). And Microsoft has contributed significant amounts of open source in the past few years. Lua is also a great language to support first-class, as its popularity is increasing more each year due to its ease of embedding.
- nine_k 8y agoLook at the number and extent of Microsoft's contributions to OpenBSD, for instance.
- charlieAutomata 8y agoDoes anyone know of any example code anywhere? I can't seem to find any public examples of someone embedding/using this. Edit: seems there is an open issues for adding some of this https://github.com/Azure/golua/issues/15 https://github.com/Azure/golua/issues/15
- mfer 8y agoIt was quietly open sourced earlier this week at an early state so we could start looking at importing it into something else (https://helm.sh https://helm.sh v3). You likely will not find any examples, yet. It's not release quality quite yet so there will likely be changes as it becomes production quality. I'm amazed people found this already. The team over there who owns this is excellent. I expect it to work nicely once they have had a little time to get everything together.
- skybrian 8y agoBased on my experience porting Wren's interpreter to Go, I would expect this to be about 3x slower than a C interpreter (without JIT). But someday I hope to be pleasantly surprised. I don't believe Go has been optimized for compiling an interpreter, so perhaps there is low-hanging fruit, should the Go team decide that it's a priority.
- nerpderp82 8y agoThey could fuse go func() that often call each other back to back, if someone was to model interpreter execution with go funcs.
- sephware 8y agoGo was originally intended as a systems level language, suitable for writing extremely efficient servers, dealing directly with raw bytes where needed, therefore enabling writing code at both high and low levels. VMs typically take advantage of the lowest level of code that their language supports to be as efficient as possible. There's no reason Go code can't be as fast as C++ code with enough time for optimizations, and there's no reason a VM written in Go has to be slower than any other low-level program written in Go.
- stcredzero 8y agoGo's native GC is specifically targeted for Go. To be performant, one would want GC targeted towards the language to be implemented.
- sephware 8y agoOnly if you're using Go's native GC as the Lua VM's GC, which isn't the only option.
- stcredzero 8y agoI have to confess, I've been thinking of implementing Smalltalk in Go, using its native GC as a very unoptimized GC.
- mitchtbaum 8y agoRust has good bindings for PUC Lua, but this looks like it could have several advantages over Rio's runtime. I did a quick search for any Rust bindings to Go libraries but haven't found any yet. I opened an issue in rlua to discuss bindings to golua, even though that would definitely be a separate project, but we have discussed there before other Lua runtimes. If anyone else is interested in using this library in Rust, here are those issues: https://github.com/kyren/rlua/issues/100 https://github.com/kyren/rlua/issues/100 https://github.com/kyren/rlua/issues/39 https://github.com/kyren/rlua/issues/39 Edits.. Resources found so far: https://users.rust-lang.org/t/can-rust-interface-with-go-libraries/4292/3 https://users.rust-lang.org/t/can-rust-interface-with-go-lib... https://medium.com/learning-the-go-programming-language/calling-go-functions-from-other-languages-4c7d8bcc69bf https://medium.com/learning-the-go-programming-language/call... https://github.com/softprops/shiplift https://github.com/softprops/shiplift (okay, here's a Rust interface to Go)
- mitchtbaum 8y agoshiplift uses an API. Looks like calling Go from Rust is never done. I would guess because of the huge performance hit at 3 orders of magnitude worse than C (according to the users.rust-lang link above). Will still be interesting to see how Golua impacts the wider Lua ecosystem.
- pitaj 8y agoIIRC, Go's ffi is super slow
- firdak 8y agoWould this allow Lua code to directly use Goroutines, and take advantage of Go's features for concurrency and parallelism? I'd love to see a high-level language like Lua (or Python, Ruby etc.) with good threading support. Building a language runtime in Go might be a good way to get that support more easily? While I'm wishing for things, could I have good single-threaded performance too? This would likely need a JIT, which unfortunately doesn't seem possible in Go at the moment [0]. Maybe I should give up on my desire for a high-level language and just use Go itself, where concurrency, parallelism and good performance are all available today... [0] https://github.com/golang/go/issues/20123 https://github.com/golang/go/issues/20123
- bjoli 8y agoYou have various lisps at your disposal, with my favourite Guile offering a full working Concurrent ML implementation instead of the almost-CML offered by Go.
- marmaduke 8y agoWouldn’t Clojure or Julia satisfy those criteria?
- acidtrucks 8y agoYou don't have to call it giving up. Go is pretty easy to pick up if you're used to high level languages. I would recommend reading a pretty short book called "concurrency in go" (Katherine Cox-Buday) for some really concise education on it.
- pull_my_finger 8y agoI'll admit I don't use or know Go, but I have been in the Tarantool docs lately. It is a JIT compiled "drop in replacement for Lua 5.1 or JIT" and has fibers and channels inspired from Go. https://medium.com/tarantool-database/dbms-as-an-application-server-779402dbf485 https://medium.com/tarantool-database/dbms-as-an-application...
- ksec 8y agoIt is interesting to think of Go as a C replacement, and both CLua and CRuby gets an implementation in go. [1] Are we going to see GoPython and GoJS? [1] https://github.com/goby-lang/goby https://github.com/goby-lang/goby
- thefounder 8y agoWe already have GoJS
- pjmlp 8y agoAndroid's OpenGL/Vulkan debugger, Fucshia TCP/IP stack, some driver research, a GCloud hypervisor, a basic POSIX kernel implementation presented at this year's USENIX are some of the examples of Go as C replacement.
- jimsmart 8y agoThere is also already a Python-implemented-in-Go[1] and a Python-to-Go transpiler[2] — albeit both somewhat limited. [1] https://github.com/go-python/gpython https://github.com/go-python/gpython [2] https://github.com/google/grumpy https://github.com/google/grumpy
- aeosynth 8y agohttps://github.com/google/starlark-go https://github.com/google/starlark-go > Starlark is a dialect of Python intended for use as a configuration language
- swah 8y agoFunny that luac is called: https://github.com/Azure/golua/blob/24b0595f74412f2f249fbdb38bb5efa2c349a07e/lua/state.go#L332 https://github.com/Azure/golua/blob/24b0595f74412f2f249fbdb3... Isn't this a pure Go implementation?
- glibgil 8y agoluac is the Lua compiler, not a reflection of what language the engine is written in. I'm not saying it doesn't call a compiler written in C, but executing a binary named `luac` doesn't mean that it does https://www.lua.org/manual/5.3/luac.html https://www.lua.org/manual/5.3/luac.html
- sdfpoi8g98sd 8y agoYou should read the source you are linking to instead of being needlessly snarky. The function you call emits IR, and it's doc block says: // EmitIR compiles the Lua script similarly to Compile but instead // uses the long listing options to capture the compiled IR dump. // EmitIR returns the Lua bytecode encoded as a string or any error.
- mysti 8y agoMay I point at my own implementation: https://github.com/arnodel/golua https://github.com/arnodel/golua
- crawdog 8y agoHeres an old project I wrote with some sample code for the C binding library. I tried the go versions and always found the c binding faster. https://github.com/rickcrawford/go-lua-test https://github.com/rickcrawford/go-lua-test