* when exception happened, use this api to tell thinkyoung * @param L the lua stack * @param code error code, 0 is OK, other is different error * @param error_format error info string, will be released by lua * @param ... error arguments */
| 72 | * @param ... error arguments |
| 73 | */ |
| 74 | void GluaChainApi::throw_exception(lua_State *L, int code, const char *error_format, ...) |
| 75 | { |
| 76 | has_error = 1; |
| 77 | char *msg = (char*)lua_malloc(L, LUA_EXCEPTION_MULTILINE_STRNG_MAX_LENGTH); |
| 78 | memset(msg, 0x0, LUA_EXCEPTION_MULTILINE_STRNG_MAX_LENGTH); |
| 79 | |
| 80 | va_list vap; |
| 81 | va_start(vap, error_format); |
| 82 | // printf(error_format, vap); |
| 83 | // const char *msg = luaO_pushfstring(L, error_format, vap); |
| 84 | vsnprintf(msg, LUA_EXCEPTION_MULTILINE_STRNG_MAX_LENGTH, error_format, vap); |
| 85 | va_end(vap); |
| 86 | if (strlen(msg) > LUA_EXCEPTION_MULTILINE_STRNG_MAX_LENGTH - 1) |
| 87 | { |
| 88 | msg[LUA_EXCEPTION_MULTILINE_STRNG_MAX_LENGTH - 1] = 0; |
| 89 | } |
| 90 | //perror(msg); |
| 91 | //printf("\n"); |
| 92 | // luaL_error(L, error_format); // notify lua error |
| 93 | //FC_THROW(msg); |
| 94 | |
| 95 | lua_set_compile_error(L, msg); |
| 96 | |
| 97 | //如果上次的exception code为THINKYOUNG_API_LVM_LIMIT_OVER_ERROR, 不能被其他异常覆盖 |
| 98 | //只有调用clear清理后,才能继续记录异常 |
| 99 | int last_code = lua::lib::get_lua_state_value(L, "exception_code").int_value; |
| 100 | if (last_code == THINKYOUNG_API_LVM_LIMIT_OVER_ERROR |
| 101 | && code != THINKYOUNG_API_LVM_LIMIT_OVER_ERROR) |
| 102 | { |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | GluaStateValue val_code; |
| 107 | val_code.int_value = code; |
| 108 | |
| 109 | GluaStateValue val_msg; |
| 110 | val_msg.string_value = msg; |
| 111 | |
| 112 | lua::lib::set_lua_state_value(L, "exception_code", val_code, GluaStateValueType::LUA_STATE_VALUE_INT); |
| 113 | lua::lib::set_lua_state_value(L, "exception_msg", val_msg, GluaStateValueType::LUA_STATE_VALUE_STRING); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * check whether the contract apis limit over, in this lua_State |
no test coverage detected