aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-12-19 12:01:00 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-12-19 12:05:04 +0100
commitc75264aa701574f9f809b1287d484a9ba8f7c5a6 (patch)
tree33c21552f98ce37d6e86427991ca717bff2e7de4
parent634b0c8415be1ec68af9ecba42d1c915b7aa7fc9 (diff)
downloadvis-c75264aa701574f9f809b1287d484a9ba8f7c5a6.tar.gz
vis-c75264aa701574f9f809b1287d484a9ba8f7c5a6.tar.xz
vis-lua: simplify obj_ref_new error handling
-rw-r--r--vis-lua.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/vis-lua.c b/vis-lua.c
index 39f99c4..3a27168 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -374,8 +374,10 @@ static void obj_ref_free(lua_State *L, void *addr) {
* return registry["vis.objects"][addr];
*/
static void *obj_ref_new(lua_State *L, void *addr, const char *type) {
- if (!addr)
+ if (!addr) {
+ lua_pushnil(L);
return NULL;
+ }
lua_getfield(L, LUA_REGISTRYINDEX, "vis.objects");
lua_pushlightuserdata(L, addr);
lua_gettable(L, -2);
@@ -556,9 +558,8 @@ static int windows_iter(lua_State *L) {
if (!*handle)
return 0;
Win *win = obj_ref_new(L, *handle, "vis.window");
- if (!win)
- return 0;
- *handle = win->next;
+ if (win)
+ *handle = win->next;
return 1;
}
@@ -585,9 +586,8 @@ static int files_iter(lua_State *L) {
if (!*handle)
return 0;
File *file = obj_ref_new(L, *handle, "vis.file");
- if (!file)
- return 0;
- *handle = file->next;
+ if (file)
+ *handle = file->next;
return 1;
}
@@ -650,10 +650,9 @@ static int message(lua_State *L) {
static int open(lua_State *L) {
Vis *vis = obj_ref_check(L, 1, "vis");
const char *name = luaL_checkstring(L, 2);
- File *file = NULL;
if (vis_window_new(vis, name))
- file = obj_ref_new(L, vis->win->file, "vis.file");
- if (!file)
+ obj_ref_new(L, vis->win->file, "vis.file");
+ else
lua_pushnil(L);
return 1;
}