diff --git a/vm_test.go b/vm_test.go index 333942b..0040a8e 100644 --- a/vm_test.go +++ b/vm_test.go @@ -23,6 +23,27 @@ skills = {"typescript", "unity", "lua"} } local json_str = json.encode(lua_table) print(json_str) -- 输出JSON字符串`, + + "http": ` +local http = require("http.request") + +-- 创建一个HTTP请求的选项表 +local options = { + url = "http://example.com", + method = "GET", +} + +-- 发起请求 +local res, code = http.request(options) + +-- 检查请求是否成功 +if code == 200 then + print("请求成功,下面是返回内容:") + print(res) +else + print("请求失败,状态码:" .. code) +end +`, } if err := InitVM(1024, nil, scriptTable); err != nil { panic(err.Error()) @@ -30,4 +51,7 @@ print(json_str) -- 输出JSON字符串`, _, err := VMInstance.RunPreCompileScript("json") fmt.Println(err) + + _, err = VMInstance.RunPreCompileScript("http") + fmt.Println(err) }