Ejemplo n.º 1
0
static int l_new (lua_State* L)
{
	Canvas* canvas = CHECKCANVAS(L);
	ISurface* sfc = NULL;
	int type = lua_type(L, 2);

	switch (type)
	{
		// IMAGE
		// [ canvas | img_path ]
		case LUA_TSTRING: {
			sfc = ImagePlayer::renderImage(
					(char*)luaL_checkstring(L, 2));

			break;
		}

		// NEW { w, h }
		// [ canvas | w | h ]
		case LUA_TNUMBER: {
#if HAVE_COMPSUPPORT
			sfc = ((SurfaceCreator*)(
					cm->getObject("Surface")))(
							NULL,
							luaL_checkint(L, 2),
							luaL_checkint(L, 3));

			sfc->setBgColor(canvas->color);
			sfc->clearContent();
#else
			sfc = new DFBSurface(luaL_checkint(L, 2), luaL_checkint(L, 3));
			sfc->setBgColor(canvas->color);
			sfc->clearContent();
#endif
			break;
		}

		default:
			return luaL_argerror(L, 2, NULL);
	}

	return lua_createcanvas(L, sfc, 1);  // [ ... | canvas ] -> canvas
}