/* Just like malloc only on failure to allocate memory it outputs an error message */ void *_safe_alloc(size_t size, int line, const char *file) { void *ptr = malloc(size); if(!ptr) _report_error("Unable to allocate memory", line, file); return ptr; }
static int _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, l); lua_setfield(L, LUA_REGISTRYINDEX, "skynet_lua"); #ifndef NOCODECACHE luaL_requiref(L, "skynet.codecache", luacode_lib , 0); lua_pop(L,1); #endif lua_gc(L, LUA_GCRESTART, 0); char tmp[strlen(args)+1]; char *parm = tmp; strcpy(parm,args); lua_pushcfunction(L, traceback); int traceback_index = lua_gettop(L); assert(traceback_index == 1); const char * filename = parm; int r = _load(L, &parm); 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)); } _report_launcher_error(ctx); return 1; } int n=0; while(parm) { const char * arg = strsep(&parm, " \r\n"); if (arg && arg[0]!='\0') { lua_pushstring(L, arg); ++n; } } r = lua_pcall(L,n,0,traceback_index); if (r == LUA_OK) { r = lua_gc(L, LUA_GCCOLLECT, 0); if (r == LUA_OK) { return 0; } } _report_error(L, ctx, filename, r); _report_launcher_error(ctx); return 1; }
NSAPI_PUBLIC void report_warning(int type, char *info, char *details) { _report_error(type, info, details, 0); }