Neatened l_graphics_setCanvas and _setFont()

This commit is contained in:
rxi
2014-06-14 16:09:24 +01:00
parent 01e09e3294
commit ac6c57220e

View File

@@ -130,18 +130,14 @@ int l_graphics_getFont(lua_State *L) {
int l_graphics_setFont(lua_State *L) { int l_graphics_setFont(lua_State *L) {
font_t *oldFont = graphics_font; font_t *oldFont = graphics_font;
int argIdx = 1;
if (lua_isnoneornil(L, 1)) { if (lua_isnoneornil(L, 1)) {
/* If no arguments are given we use the default embedded font, grab it /* If no arguments are given we use the default embedded font, grab it
* from the registry and get its index */ * from the registry and set it as the first argument */
graphics_font = graphics_defaultFont;
lua_pushlightuserdata(L, &graphics_defaultFont); lua_pushlightuserdata(L, &graphics_defaultFont);
lua_gettable(L, LUA_REGISTRYINDEX); lua_gettable(L, LUA_REGISTRYINDEX);
argIdx = lua_absindex(L, -1); lua_insert(L, 1);
} else {
/* Set argument font */
graphics_font = luaobj_checkudata(L, 1, LUAOBJ_TYPE_FONT);
} }
graphics_font = luaobj_checkudata(L, 1, LUAOBJ_TYPE_FONT);
/* Remove old font from registry. This is done after we know the args are /* Remove old font from registry. This is done after we know the args are
* so that the font remains unchanged if an error occurs */ * so that the font remains unchanged if an error occurs */
if (oldFont) { if (oldFont) {
@@ -151,7 +147,7 @@ int l_graphics_setFont(lua_State *L) {
} }
/* Add new font to registry */ /* Add new font to registry */
lua_pushlightuserdata(L, graphics_font); lua_pushlightuserdata(L, graphics_font);
lua_pushvalue(L, argIdx); lua_pushvalue(L, 1);
lua_settable(L, LUA_REGISTRYINDEX); lua_settable(L, LUA_REGISTRYINDEX);
return 0; return 0;
} }
@@ -166,18 +162,14 @@ int l_graphics_getCanvas(lua_State *L) {
int l_graphics_setCanvas(lua_State *L) { int l_graphics_setCanvas(lua_State *L) {
image_t *oldCanvas = graphics_canvas; image_t *oldCanvas = graphics_canvas;
int argIdx = 1;
if (lua_isnoneornil(L, 1)) { if (lua_isnoneornil(L, 1)) {
/* If no arguments are given we use the screen canvas, grab it from the /* If no arguments are given we use the screen canvas, grab it from the
* registry and get its index */ * registry and get its index */
graphics_canvas = graphics_screen;
lua_pushlightuserdata(L, &graphics_screen); lua_pushlightuserdata(L, &graphics_screen);
lua_gettable(L, LUA_REGISTRYINDEX); lua_gettable(L, LUA_REGISTRYINDEX);
argIdx = lua_absindex(L, -1); lua_insert(L, 1);
} else { }
/* Set argument canvas */ graphics_canvas = luaobj_checkudata(L, 1, LUAOBJ_TYPE_IMAGE);
graphics_canvas = luaobj_checkudata(L, 1, LUAOBJ_TYPE_IMAGE);
}
/* Remove old canvas from registry. This is done after we know the args are /* Remove old canvas from registry. This is done after we know the args are
* so that the canvas remains unchanged if an error occurs */ * so that the canvas remains unchanged if an error occurs */
if (oldCanvas) { if (oldCanvas) {
@@ -187,7 +179,7 @@ int l_graphics_setCanvas(lua_State *L) {
} }
/* Add new canvas to registry */ /* Add new canvas to registry */
lua_pushlightuserdata(L, graphics_canvas); lua_pushlightuserdata(L, graphics_canvas);
lua_pushvalue(L, argIdx); lua_pushvalue(L, 1);
lua_settable(L, LUA_REGISTRYINDEX); lua_settable(L, LUA_REGISTRYINDEX);
return 0; return 0;
} }