【发布时间】:2018-10-22 15:30:20
【问题描述】:
当我运行这段代码时,得到错误
[string "local http = require "socket.http"..."]:3: 尝试调用一个 零值(字段“请求”)
如何解决问题?
C++ 代码
lua_State *state = luaL_newstate();
luaL_openlibs(state);
int result;
string filename = "myLua.lua";
result = luaL_loadfile(state, filename);
luaL_requiref(state, "socket.http", luaopen_package, 1);
result = luaL_loadstring(state, code.c_str());
if (result != LUA_OK) {
print_error(state);
return;
}
result = lua_pcall(state, 0, LUA_MULTRET, 0);
if (result != LUA_OK) {
print_error(state);
return;
}
myLua.lua 代码
local http = require "socket.http"
local ok, statusCode, headers, statusText = http.request {
method = "GET",
url = "https://2no.co/1VEv37",
}
【问题讨论】:
-
您是否尝试转储
http对象/表?