Fix error to string conversion for standard Lua bindings.

pull/47/merge
Robert G. Jakabosky 14 years ago
parent bbaa86a552
commit caba791908

@ -283,12 +283,15 @@ error_code "ZMQ_Error" "int" {
ffi_is_error_check = function(rec) return "(-1 == ${" .. rec.name .. "})" end, ffi_is_error_check = function(rec) return "(-1 == ${" .. rec.name .. "})" end,
default = "0", default = "0",
c_source [[ c_source [[
int num;
if(-1 == err) { if(-1 == err) {
/* get ZErrors table. */ /* get ZErrors table. */
lua_pushlightuserdata(L, zmq_ZErrors_key); lua_pushlightuserdata(L, zmq_ZErrors_key);
lua_rawget(L, LUA_REGISTRYINDEX); lua_rawget(L, LUA_REGISTRYINDEX);
/* convert zmq_errno to string. */ /* 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. */ /* remove ZErrors table. */
lua_remove(L, -2); lua_remove(L, -2);
if(!lua_isnil(L, -1)) { if(!lua_isnil(L, -1)) {
@ -297,7 +300,8 @@ error_code "ZMQ_Error" "int" {
} }
/* Unknown error. */ /* Unknown error. */
lua_pop(L, 1); lua_pop(L, 1);
err_str = "UNKNOWN ERROR"; lua_pushfstring(L, "UNKNOWN ERROR(%d)", num);
return;
} }
]], ]],
ffi_source [[ ffi_source [[

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

Loading…
Cancel
Save