summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/lua/rocklib.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 1560f19d9e..22e86f91b7 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -184,8 +184,7 @@ static inline void rli_init(lua_State *L)
184/* Helper function for opt_viewport */ 184/* Helper function for opt_viewport */
185static void check_tablevalue(lua_State *L, const char* key, int tablepos, void* res, bool unsigned_val) 185static void check_tablevalue(lua_State *L, const char* key, int tablepos, void* res, bool unsigned_val)
186{ 186{
187 lua_pushstring(L, key); /* Push the key on the stack */ 187 lua_getfield(L, tablepos, key); /* Find table[key] */
188 lua_gettable(L, tablepos); /* Find table[key] (pops key off the stack) */
189 188
190 if(!lua_isnoneornil(L, -1)) 189 if(!lua_isnoneornil(L, -1))
191 { 190 {
@@ -204,11 +203,22 @@ static struct viewport* opt_viewport(lua_State *L, int narg, struct viewport* al
204 return alt; 203 return alt;
205 204
206 int tablepos = lua_gettop(L); 205 int tablepos = lua_gettop(L);
206 struct viewport *vp;
207 207
208 lua_pushliteral(L, "vp"); /* push 'vp' on the stack */ 208 lua_getfield(L, tablepos, "vp"); /* get table['vp'] */
209 struct viewport *vp = (struct viewport*)lua_newuserdata(L, sizeof(struct viewport)); /* allocate memory and push it as udata on the stack */ 209 if(lua_isnoneornil(L, -1))
210 memset(vp, 0, sizeof(struct viewport)); /* Init viewport values to 0 */ 210 {
211 lua_settable(L, tablepos); /* table['vp'] = vp (pops key & value off the stack) */ 211 lua_pop(L, 1); /* Pop nil off stack */
212
213 vp = (struct viewport*) lua_newuserdata(L, sizeof(struct viewport)); /* Allocate memory and push it as udata on the stack */
214 memset(vp, 0, sizeof(struct viewport)); /* Init viewport values to 0 */
215 lua_setfield(L, tablepos, "vp"); /* table['vp'] = vp (pops value off the stack) */
216 }
217 else
218 {
219 vp = (struct viewport*) lua_touserdata(L, -1); /* Reuse viewport struct */
220 lua_pop(L, 1); /* We don't need the value on stack */
221 }
212 222
213 luaL_checktype(L, narg, LUA_TTABLE); 223 luaL_checktype(L, narg, LUA_TTABLE);
214 224