最近看到golang里面有人实现了一套lua的调用库。
go-lua
https://github.com/yuin/gopher-lua
github.com/aarzilli/golua/lua
性能对比
This exercises the call stack implementation. When computing fib(35)
, go-lua is about 6x slower than the C Lua interpreter. Gopher-lua is about 20% faster than go-lua. Much of the performance difference between go-lua and gopher-lua comes from the inclusion of debug hooks in go-lua. The remainder is due to the call stack implementation - go-lua heap-allocates Lua stack frames with a separately allocated variant struct, as outlined above. Although it caches recently used stack frames, it is outperformed by the simpler statically allocated call stacks in gopher-lua.
$ time lua fibr.lua
real 0m2.807s
user 0m2.795s
sys 0m0.006s
$ time glua fibr.lua
real 0m14.528s
user 0m14.513s
sys 0m0.031s
$ time go-lua fibr.lua
real 0m17.411s
user 0m17.514s
sys 0m1.287s
这套方案,是使用golang完整编写了一套lua vm,性能非常差。而且这套东西是不能兼容使用C语言编写的三方库lua库,打比方就是protobuf-c的库就无法使用。其实这样就局限了这套代码的用途了。如果是使用来编写一些简单的逻辑,是可以的。做做配置也是不错,但是其他的事情,这个是不合适的。