static int canvas_cairo_file_lua_new_generic(lua_State *L, GtGraphicsOutType t) { GtCanvas **canvas; GtImageInfo **ii; unsigned int width, height; GtError *err; GtStyle *style; width = luaL_checkint(L, 1); height = luaL_checkint(L, 2); /* create canvas */ style = gt_lua_get_style_from_registry(L); canvas = lua_newuserdata(L, sizeof (GtCanvas*)); gt_assert(canvas); /* if a imageinfo object is passed, it must be correct type */ if (lua_isnil(L, 3)) { err = gt_error_new(); *canvas = gt_canvas_cairo_file_new(style, t, width, height, NULL, err); } else { ii = check_imageinfo(L, 3); err = gt_error_new(); *canvas = gt_canvas_cairo_file_new(style, t, width, height, *ii, err); } if (gt_error_is_set(err)) return gt_lua_error(L, err); gt_error_delete(err); luaL_getmetatable(L, CANVAS_METATABLE); lua_setmetatable(L, -2); return 1; }
static int layout_lua_new(lua_State *L) { GtLayout **layout; GtDiagram **diagram; unsigned int width; GtStyle *style; GtError *err; diagram = check_diagram(L, 1); width = luaL_checkint(L, 2); /* create layout */ style = gt_lua_get_style_from_registry(L); layout = lua_newuserdata(L, sizeof (GtLayout*)); gt_assert(layout); err = gt_error_new(); *layout = gt_layout_new(*diagram, width, style, err); if (gt_error_is_set(err)) return gt_lua_error(L, err); gt_error_delete(err); luaL_getmetatable(L, LAYOUT_METATABLE); lua_setmetatable(L, -2); return 1; }