| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- /*
- * This source file is part of libRocket, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://www.librocket.com
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
- #include "precompiled.h"
- #include "Colourb.h"
- namespace Rocket {
- namespace Core {
- namespace Lua {
- template<> void ExtraInit<Colourb>(lua_State* L, int metatable_index)
- {
- lua_pushcfunction(L,Colourbnew);
- lua_setfield(L,metatable_index-1,"new");
- lua_pushcfunction(L,Colourb__eq);
- lua_setfield(L,metatable_index,"__eq");
- lua_pushcfunction(L,Colourb__add);
- lua_setfield(L,metatable_index,"__add");
- lua_pushcfunction(L,Colourb__mul);
- lua_setfield(L,metatable_index,"__mul");
- return;
- }
- int Colourbnew(lua_State* L)
- {
- byte red = (byte)luaL_checkinteger(L,1);
- byte green = (byte)luaL_checkinteger(L,2);
- byte blue = (byte)luaL_checkinteger(L,3);
- byte alpha = (byte)luaL_checkinteger(L,4);
- Colourb* col = new Colourb(red,green,blue,alpha);
- LuaType<Colourb>::push(L,col,true);
- return 1;
- }
- int Colourb__eq(lua_State* L)
- {
- Colourb* lhs = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(lhs);
- Colourb* rhs = LuaType<Colourb>::check(L,2);
- LUACHECKOBJ(rhs);
- lua_pushboolean(L, (*lhs) == (*rhs) ? 1 : 0);
- return 1;
- }
- int Colourb__add(lua_State* L)
- {
- Colourb* lhs = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(lhs);
- Colourb* rhs = LuaType<Colourb>::check(L,2);
- LUACHECKOBJ(rhs);
- Colourb* res = new Colourb((*lhs) + (*rhs));
- LuaType<Colourb>::push(L,res,true);
- return 1;
- }
- int Colourb__mul(lua_State* L)
- {
- Colourb* lhs = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(lhs);
- float rhs = (float)luaL_checknumber(L,2);
- Colourb* res = new Colourb((*lhs) * rhs);
-
- LuaType<Colourb>::push(L,res,true);
- return 1;
- }
- //getters
- int ColourbGetAttrred(lua_State* L)
- {
- Colourb* obj = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(obj);
- lua_pushinteger(L,obj->red);
- return 1;
- }
- int ColourbGetAttrgreen(lua_State* L)
- {
- Colourb* obj = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(obj);
- lua_pushinteger(L,obj->green);
- return 1;
- }
- int ColourbGetAttrblue(lua_State* L)
- {
- Colourb* obj = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(obj);
- lua_pushinteger(L,obj->blue);
- return 1;
- }
- int ColourbGetAttralpha(lua_State* L)
- {
- Colourb* obj = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(obj);
- lua_pushinteger(L,obj->alpha);
- return 1;
- }
- int ColourbGetAttrrgba(lua_State* L)
- {
- Colourb* obj = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(obj);
- lua_pushinteger(L,obj->red);
- lua_pushinteger(L,obj->green);
- lua_pushinteger(L,obj->blue);
- lua_pushinteger(L,obj->alpha);
- return 4;
- }
- //setters
- int ColourbSetAttrred(lua_State* L)
- {
- Colourb* obj = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(obj);
- byte red = (byte)luaL_checkinteger(L,2);
- obj->red = red;
- return 0;
- }
- int ColourbSetAttrgreen(lua_State* L)
- {
- Colourb* obj = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(obj);
- byte green = (byte)luaL_checkinteger(L,2);
- obj->green = green;
- return 0;
- }
- int ColourbSetAttrblue(lua_State* L)
- {
- Colourb* obj = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(obj);
- byte blue = (byte)luaL_checkinteger(L,2);
- obj->blue = blue;
- return 0;
- }
- int ColourbSetAttralpha(lua_State* L)
- {
- Colourb* obj = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(obj);
- byte alpha = (byte)luaL_checkinteger(L,2);
- obj->alpha = alpha;
- return 0;
- }
- int ColourbSetAttrrgba(lua_State* L)
- {
- Colourb* obj = NULL;
- int top = lua_gettop(L);
- //each of the items are optional.
- if(top > 0)
- {
- obj = LuaType<Colourb>::check(L,1);
- LUACHECKOBJ(obj);
- if(top > 1)
- {
- if(top > 2)
- {
- if(top > 3)
- obj->alpha = luaL_checkinteger(L,4);
- obj->blue = luaL_checkinteger(L,3);
- }
- obj->green = luaL_checkinteger(L,2);
- }
- obj->red = luaL_checkinteger(L,1);
- }
- return 0;
- }
- RegType<Colourb> ColourbMethods[] =
- {
- { NULL, NULL },
- };
- luaL_Reg ColourbGetters[] =
- {
- LUAGETTER(Colourb,red)
- LUAGETTER(Colourb,green)
- LUAGETTER(Colourb,blue)
- LUAGETTER(Colourb,alpha)
- LUAGETTER(Colourb,rgba)
- { NULL, NULL },
- };
- luaL_Reg ColourbSetters[] =
- {
- LUASETTER(Colourb,red)
- LUASETTER(Colourb,green)
- LUASETTER(Colourb,blue)
- LUASETTER(Colourb,alpha)
- LUASETTER(Colourb,rgba)
- { NULL, NULL },
- };
- LUACORETYPEDEFINE(Colourb,false)
- }
- }
- }
|