mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
reload snlua service
This commit is contained in:
@@ -4,17 +4,13 @@
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
#include "luacompat52.h"
|
||||
#include "service_lua.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
lua_State *
|
||||
snlua_create(void) {
|
||||
return luaL_newstate();
|
||||
}
|
||||
|
||||
static int
|
||||
_try_load(lua_State *L, const char * path, int pathlen, const char * name) {
|
||||
int namelen = strlen(name);
|
||||
@@ -102,12 +98,14 @@ traceback (lua_State *L) {
|
||||
}
|
||||
|
||||
int
|
||||
snlua_init(lua_State *L, struct skynet_context *ctx, const char * args) {
|
||||
snlua_init(struct snlua *l, struct skynet_context *ctx, const char * args) {
|
||||
lua_State *L = l->L;
|
||||
l->ctx = ctx;
|
||||
luaL_init(L);
|
||||
lua_gc(L, LUA_GCSTOP, 0);
|
||||
luaL_openlibs(L);
|
||||
lua_pushlightuserdata(L, ctx);
|
||||
lua_setfield(L, LUA_REGISTRYINDEX, "skynet_context");
|
||||
lua_pushlightuserdata(L, l);
|
||||
lua_setfield(L, LUA_REGISTRYINDEX, "skynet_lua");
|
||||
lua_gc(L, LUA_GCRESTART, 0);
|
||||
|
||||
char tmp[strlen(args)+1];
|
||||
@@ -159,7 +157,17 @@ snlua_init(lua_State *L, struct skynet_context *ctx, const char * args) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
snlua_release(lua_State *L) {
|
||||
lua_close(L);
|
||||
struct snlua *
|
||||
snlua_create(void) {
|
||||
struct snlua * l = malloc(sizeof(*l));
|
||||
memset(l,0,sizeof(*l));
|
||||
l->L = luaL_newstate();
|
||||
l->init = snlua_init;
|
||||
return l;
|
||||
}
|
||||
|
||||
void
|
||||
snlua_release(struct snlua *l) {
|
||||
lua_close(l->L);
|
||||
free(l);
|
||||
}
|
||||
|
||||
11
service-src/service_lua.h
Normal file
11
service-src/service_lua.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef SKYNET_SERVICE_LUA_H
|
||||
#define SKYNET_SERVICE_LUA_H
|
||||
|
||||
struct snlua {
|
||||
lua_State * L;
|
||||
const char * reload;
|
||||
struct skynet_context * ctx;
|
||||
int (*init)(struct snlua *l, struct skynet_context *ctx, const char * args);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user