

GopherLua: VM and Compiler for Lua in Go - tombenner
https://github.com/yuin/gopher-lua

======
nsjph
On a similar note, there's a clojure-like (syntax) embeddable VM called glisp:
[https://github.com/zhemao/glisp](https://github.com/zhemao/glisp). I've been
tinkering with it to add dynamic plugins to some golang programs.

I'd be interested if someone were to benchmark it against GopherLua.

------
kibwen
Interesting that it implements Lua 5.1 rather than any of the newer versions.
Is it because LuaJIT implements 5.1, thereby making that the de facto
canonical language version?

~~~
trynumber9
Lua 5.1 is the most widely used. LuaJIT is a big factor. But changing existing
code to use the 5.2 API is not worth the few changes 5.2 offered. The 5.1 API
has the most libraries. Many existing code bases try to stay compatible with
5.1.

This situation may change as 5.3 adds many nice changes.

------
haberman
From a quick glance at the source, it looks like this may be a port of the
existing Lua VM for C into Go.

For example, it appears to use the same opcodes and the main VM loop looks
very similar:

[http://www.lua.org/source/5.1/lvm.c.html](http://www.lua.org/source/5.1/lvm.c.html)

[https://github.com/yuin/gopher-
lua/blob/master/vm.go](https://github.com/yuin/gopher-lua/blob/master/vm.go)

It's interesting because the Go source appears to be annotating certain
patterns with comments where the C version uses a macro. Compare the C
version:

    
    
            case OP_LOADK: {
              setobj2s(L, ra, KBx(i));
    

With the Go version:

    
    
            case OP_LOADK:
                    Bx = int(inst & 0x3ffff) //GETBX
                    reg.Set(RA, cf.Fn.Proto.Constants[Bx])

~~~
SixSigma
And what a useless comment GETBX is.

------
lclarkmichalek
Well it certainly beats javascript on the fibonacci benchmark, clearly this is
the language of the future.

~~~
blt
Stupidest benchmark ever. Tests nothing but procedure call speed.

~~~
munificent
Procedure call speed does matter.

------
m0sia
Is it any way better/faster than luajit or vanilla lua? I can't understand why
people are so excited about it.

~~~
sztanpet
The excitement is because Lua is a very nice little language with the explicit
goal of being embedded into programs, so when a pure-go port of the language
appears that is not just bindings to the C version it is warmly welcomed.

And no, it shouldn't be any faster than luajit (what can really :)

------
giancarlostoro
Been waiting for someone to make languages in Go to see the results

~~~
ndrscr
Reminds me of this:
[https://twitter.com/Steve_Yegge/status/372156022913122304](https://twitter.com/Steve_Yegge/status/372156022913122304)

~~~
Intermernet
That's a brilliant comment!

I've noticed that Go seems to be fairly popular for emulators / simple VMs as
well. I'm currently working on a SID emulator in Go, and I'm finding it quite
fun! (unfortunately, it means that I then need to write a proof of concept
synth-like API to the SID, then a proof of concept sequencer to control the
synth...)

Damn rabbit holes.

