From 3ab068905e0641e9d046ee3894a7c12e58bad481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Mon, 13 Aug 2012 16:02:08 +0800 Subject: [PATCH] snlua support multi-path --- config | 2 +- service-src/service_lua.c | 72 ++++++++++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/config b/config index 5d4e0950..54bdc917 100644 --- a/config +++ b/config @@ -7,6 +7,6 @@ address = "tcp://127.0.0.1:2525" master = "tcp://127.0.0.1:2012" start = "main" standalone = true -luaservice = root.."service/?.lua" +luaservice = root.."service/?.lua;"..root.."service/?/init.lua" cpath = root.."service/?.so" protopath = root.."proto" diff --git a/service-src/service_lua.c b/service-src/service_lua.c index 64916ff9..e3b3f8de 100644 --- a/service-src/service_lua.c +++ b/service-src/service_lua.c @@ -6,6 +6,7 @@ #include #include +#include lua_State * snlua_create(void) { @@ -13,26 +14,67 @@ snlua_create(void) { } static int -_load(lua_State *L, char ** filename) { - const char * name = strsep(filename, " \r\n"); - const char * path = skynet_command(NULL, "GETENV", "luaservice"); - int namesz = strlen(name); - int sz = strlen(path) + namesz; - char tmp[sz]; +_try_load(lua_State *L, const char * path, int pathlen, const char * name) { + int namelen = strlen(name); + char tmp[pathlen + namelen]; int i; - for (i=0;path[i]!='?' && path[i]!='\0';i++) { + for (i=0;i=0) { + return r; + } + path+=pathlen; + if (path[0]==';') + ++path; + } + return -1; } static int @@ -63,8 +105,12 @@ snlua_init(lua_State *L, struct skynet_context *ctx, const char * args) { const char * filename = parm; int r = _load(L, &parm); - if (r) { - skynet_error(ctx, "lua parser [%s] error : %s", filename, lua_tostring(L,-1)); + if (r != 0) { + if (r<0) { + skynet_error(ctx, "lua parser [%s] load error", filename); + } else { + skynet_error(ctx, "lua parser [%s] error : %s", filename, lua_tostring(L,-1)); + } return 1; } int n=0;