Optimize the lua_c module
This commit is contained in:
parent
7e32a84d2c
commit
d3b65df599
|
|
@ -11,8 +11,7 @@
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
#include "../c/ip2region.h"
|
#include "../c/ip2region.h"
|
||||||
|
|
||||||
#define L_METATABLE_NAME "Ip2region"
|
#define L_METATABLE_NAME "Ip2region_MT"
|
||||||
|
|
||||||
|
|
||||||
/** create a new ip2region object with a specified dbFile */
|
/** create a new ip2region object with a specified dbFile */
|
||||||
static int lua_ip2region_new(lua_State *L)
|
static int lua_ip2region_new(lua_State *L)
|
||||||
|
|
@ -186,8 +185,8 @@ static int lua_ip2region_tostring(lua_State *L)
|
||||||
|
|
||||||
/** module method array */
|
/** module method array */
|
||||||
static const struct luaL_Reg ip2region_methods[] = {
|
static const struct luaL_Reg ip2region_methods[] = {
|
||||||
{ "new", lua_ip2region_new },
|
// { "new", lua_ip2region_new },
|
||||||
{ "ip2long", lua_ip2long },
|
// { "ip2long", lua_ip2long },
|
||||||
{ "memorySearch", lua_ip2region_memory_search },
|
{ "memorySearch", lua_ip2region_memory_search },
|
||||||
{ "binarySearch", lua_ip2region_binary_search },
|
{ "binarySearch", lua_ip2region_binary_search },
|
||||||
{ "btreeSearch", lua_ip2region_btree_search },
|
{ "btreeSearch", lua_ip2region_btree_search },
|
||||||
|
|
@ -197,6 +196,13 @@ static const struct luaL_Reg ip2region_methods[] = {
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** module function array */
|
||||||
|
static const struct luaL_Reg ip2region_functions[] = {
|
||||||
|
{ "new", lua_ip2region_new },
|
||||||
|
{ "ip2long", lua_ip2long },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
/** module open function interface */
|
/** module open function interface */
|
||||||
int luaopen_Ip2region(lua_State *L)
|
int luaopen_Ip2region(lua_State *L)
|
||||||
{
|
{
|
||||||
|
|
@ -216,6 +222,11 @@ int luaopen_Ip2region(lua_State *L)
|
||||||
* access via object:func in lua block
|
* access via object:func in lua block
|
||||||
*/
|
*/
|
||||||
luaL_setfuncs(L, ip2region_methods, 0);
|
luaL_setfuncs(L, ip2region_methods, 0);
|
||||||
|
luaL_setfuncs(L, ip2region_functions, 0);
|
||||||
|
|
||||||
|
/* Finally register the object.func functions
|
||||||
|
* into the table witch at the top of the stack */
|
||||||
|
// luaL_newlib(L, ip2region_functions);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ while ( true ) do
|
||||||
break;
|
break;
|
||||||
elseif ( line == "quit" ) then
|
elseif ( line == "quit" ) then
|
||||||
break;
|
break;
|
||||||
elseif ( ip2region.ip2long(line) == nil ) then
|
elseif ( Ip2region.ip2long(line) == nil ) then
|
||||||
print("Invalid ip address=", line);
|
print("Invalid ip address=", line);
|
||||||
else
|
else
|
||||||
local data;
|
local data;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue