集成 github.com/vadv/gopher-lua-libs, 并支持 dkjson

This commit is contained in:
2025-05-12 16:40:33 +08:00
parent a95acc7e36
commit 3253191437
14 changed files with 2811 additions and 4 deletions

View File

@ -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)
}