Skip to content

Commit

Permalink
Fix error to string conversion for standard Lua bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neopallium committed Mar 22, 2012
1 parent bbaa86a commit caba791
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/error.nobj.lua
Expand Up @@ -283,12 +283,15 @@ error_code "ZMQ_Error" "int" {
ffi_is_error_check = function(rec) return "(-1 == ${" .. rec.name .. "})" end,
default = "0",
c_source [[
int num;
if(-1 == err) {
/* get ZErrors table. */
lua_pushlightuserdata(L, zmq_ZErrors_key);
lua_rawget(L, LUA_REGISTRYINDEX);
/* convert zmq_errno to string. */
lua_rawgeti(L, -1, zmq_errno());
num = zmq_errno();
lua_pushinteger(L, num);
lua_gettable(L, -2);
/* remove ZErrors table. */
lua_remove(L, -2);
if(!lua_isnil(L, -1)) {
Expand All @@ -297,7 +300,8 @@ error_code "ZMQ_Error" "int" {
}
/* Unknown error. */
lua_pop(L, 1);
err_str = "UNKNOWN ERROR";
lua_pushfstring(L, "UNKNOWN ERROR(%d)", num);
return;
}
]],
ffi_source [[
Expand Down
8 changes: 6 additions & 2 deletions src/pre_generated-zmq.nobj.c
Expand Up @@ -4002,12 +4002,15 @@ static int ZErrors____index__meth(lua_State *L) {

static void error_code__ZMQ_Error__push(lua_State *L, ZMQ_Error err) {
const char *err_str = NULL;
int num;
if(-1 == err) {
/* get ZErrors table. */
lua_pushlightuserdata(L, zmq_ZErrors_key);
lua_rawget(L, LUA_REGISTRYINDEX);
/* convert zmq_errno to string. */
lua_rawgeti(L, -1, zmq_errno());
num = zmq_errno();
lua_pushinteger(L, num);
lua_gettable(L, -2);
/* remove ZErrors table. */
lua_remove(L, -2);
if(!lua_isnil(L, -1)) {
Expand All @@ -4016,7 +4019,8 @@ static void error_code__ZMQ_Error__push(lua_State *L, ZMQ_Error err) {
}
/* Unknown error. */
lua_pop(L, 1);
err_str = "UNKNOWN ERROR";
lua_pushfstring(L, "UNKNOWN ERROR(%d)", num);
return;
}

if(err_str) {
Expand Down

0 comments on commit caba791

Please sign in to comment.