集成 github.com/vadv/gopher-lua-libs, 并支持 dkjson
This commit is contained in:
20
vm_test.go
20
vm_test.go
@ -8,10 +8,26 @@
|
||||
package lua
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewVm(t *testing.T) {
|
||||
v := NewVm()
|
||||
v.Run(`print("hello world"); return "hahaha", "heiheihei"`)
|
||||
scriptTable := map[string]string{
|
||||
"json": `local json = require("dkjson")
|
||||
local lua_table = {
|
||||
name = "wx771720",
|
||||
age = 18,
|
||||
married = true,
|
||||
skills = {"typescript", "unity", "lua"}
|
||||
}
|
||||
local json_str = json.encode(lua_table)
|
||||
print(json_str) -- 输出JSON字符串`,
|
||||
}
|
||||
if err := InitVM(1024, nil, scriptTable); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
_, err := VMInstance.RunPreCompileScript("json")
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user