1
0
Files
envoy-apisix/envoy/main.cpp
2023-04-14 17:12:13 +08:00

41 lines
1.0 KiB
C++

#include "envoy.h"
int callLua(lua_State* state, const char *func)
{
lua::LuaDeathRef<lua::StreamHandleWrapper> 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;
}