35 { |
35 { |
36 struct nexus_lua *lua; |
36 struct nexus_lua *lua; |
37 |
37 |
38 // alloc |
38 // alloc |
39 if ((lua = calloc(1, sizeof(*lua))) == NULL) |
39 if ((lua = calloc(1, sizeof(*lua))) == NULL) |
40 return SET_ERROR(err, ERR_CALLOC); |
40 return SET_ERROR_MEM(err); |
41 |
41 |
42 // store |
42 // store |
43 lua->nexus = nexus; |
43 lua->nexus = nexus; |
44 |
44 |
45 // create the lua state |
45 // create the lua state |
46 if ((lua->st = luaL_newstate()) == NULL) |
46 if ((lua->st = luaL_newstate()) == NULL) |
47 JUMP_SET_ERROR(err, ERR_LUA_MEM); |
47 JUMP_SET_ERROR(err, &lua_errors, ERR_LUA_MEM); |
48 |
48 |
49 // init in protected mode |
49 // init in protected mode |
50 if (nexus_lua_error(lua->st, lua_cpcall(lua->st, &nexus_lua_init, lua), err)) |
50 if (nexus_lua_error(lua->st, lua_cpcall(lua->st, &nexus_lua_init, lua), err)) |
51 goto error; |
51 goto error; |
52 |
52 |
103 { |
103 { |
104 // XXX: this can raise an erorr itself |
104 // XXX: this can raise an erorr itself |
105 const char *error = lua_tostring(L, -1); |
105 const char *error = lua_tostring(L, -1); |
106 |
106 |
107 switch (ret) { |
107 switch (ret) { |
108 case 0: RETURN_SET_ERROR(err, SUCCESS); |
108 case 0: return SUCCESS; |
109 case LUA_ERRSYNTAX: RETURN_SET_ERROR_STR(err, ERR_LUA_SYNTAX, error); |
109 case LUA_ERRSYNTAX: return SET_ERROR_STR(err, &lua_errors, ERR_LUA_SYNTAX, error); |
110 case LUA_ERRRUN: RETURN_SET_ERROR_STR(err, ERR_LUA_RUN, error); |
110 case LUA_ERRRUN: return SET_ERROR_STR(err, &lua_errors, ERR_LUA_RUN, error); |
111 case LUA_ERRMEM: RETURN_SET_ERROR_STR(err, ERR_LUA_MEM, error); |
111 case LUA_ERRMEM: return SET_ERROR_STR(err, &lua_errors, ERR_LUA_MEM, error); |
112 case LUA_ERRERR: RETURN_SET_ERROR_STR(err, ERR_LUA_ERR, error); |
112 case LUA_ERRERR: return SET_ERROR_STR(err, &lua_errors, ERR_LUA_ERR, error); |
113 case LUA_ERRFILE: RETURN_SET_ERROR_STR(err, ERR_LUA_FILE, error); |
113 case LUA_ERRFILE: return SET_ERROR_STR(err, &lua_errors, ERR_LUA_FILE, error); |
114 default: RETURN_SET_ERROR_EXTRA(err, ERR_UNKNOWN, ret); |
114 default: return SET_ERROR(err, &general_errors, ERR_UNKNOWN); |
115 }; |
115 }; |
116 } |
116 } |
117 |
117 |