Lua入口线程中止:运行时错误:表溢出

我是 Lua 和 Nginx 的新手。我有一个 Lua 文件,用于验证任何请求击中 NGINX。

local ffi = require("ffi")
local cjson = require("cjson")
local iam = ffi.load("/gateway/auth/main/libiam.so")

ffi.cdef([[
  typedef long long GoInt64;
  typedef GoInt64 GoInt;
  typedef struct { const char *p; GoInt n; } GoString;
  extern GoInt VerifyToken(GoString p0);
  extern GoInt64 VerifyApiKey(GoString p0);
]]);

local accessToken = ""
local apiKey = ""
local result = 0
local typeString = ffi.typeof("GoString")
local unauthorizedJson={}

如果 ngx.var.http_Authorization 和 string.len(ngx.var.http_Authorization) > 0 then
      如果 ngx.var.http_Authorization:sub(1, #"Bearer") == "Bearer" then
        ngx.log(ngx.STDERR, '正在验证令牌。')
        accessToken = string.sub(ngx.var.http_Authorization,8)
        local  accessTokenString= typeString(accessToken, string.len(accessToken))
        result = iam.VerifyToken(accessTokenString)
      else

        apiKey = ngx.var.http_Authorization
        local  apiKeyString= typeString(apiKey, string.len(apiKey))
        result = iam.VerifyApiKey(apiKeyString)
      end
      如果 tonumber(result)~=0 then
        -- 我们在这里很好并继续路由到上游
        if string.len(apiKey) > 0 then
          ngx.req.set_header("abc", result)
        end
      else

        return ngx.exit(ngx.HTTP_UNAUTHORIZED)
      end

else

  return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end

我偶尔会看到以下错误

Lua entry thread aborted: runtime error: table overflow

在这一行

ffi.cdef([[

我正在使用 openresty。有人能告诉我这里可能出了什么问题吗?

点赞
用户4960038
用户4960038

我被纠正了。ffi[[ 和 ffi([[ 都是可以接受的。

2020-09-15 07:46:05