#include "envoy.h" int callLua(lua_State* state, const char *func) { lua::LuaDeathRef handle; lua_getglobal(state, func); if (lua_isfunction(state, -1)) { handle.reset(lua::StreamHandleWrapper::create(state), true); lua_call(state, 1, 0); } lua_pop(state, 1); return 0; } int main(int argc, char *argv[]) { if (argc < 1) { printf("usage: envoy-apisix [lua file]\n"); return 0; } lua_State* state = luaL_newstate(); luaL_openlibs(state); lua::BufferWrapper::registerType(state); lua::HeaderMapIterator::registerType(state); lua::HeaderMapWrapper::registerType(state); lua::MetadataMapWrapper::registerType(state); lua::MetadataMapIterator::registerType(state); lua::StreamInfoWrapper::registerType(state); lua::StreamHandleWrapper::registerType(state); if (luaL_dofile(state, argv[1])) { printf("script load error: %s\n", lua_tostring(state, -1)); return 0; } callLua(state, "envoy_on_request"); lua_close(state); return 0; }