Example #1
0
int MeshBinder::setColors(lua_State *L)
{
    Binder binder(L);
    GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1));

    if (lua_type(L, 2) == LUA_TTABLE)
    {
        int n = lua_objlen(L, 2);
        for (int k = 0; k < n/3; ++k)
        {
            lua_rawgeti(L, 2, k * 3 + 1);
            int i = luaL_checkinteger(L, -1) - 1;
            lua_pop(L, 1);

            lua_rawgeti(L, 2, k * 3 + 2);
            unsigned int color = luaL_checkinteger(L, -1);
            lua_pop(L, 1);

            lua_rawgeti(L, 2, k * 3 + 3);
            float alpha = luaL_checknumber(L, -1);
            lua_pop(L, 1);

            mesh->setColor(i, color, alpha);
        }
    }
    else
    {
        int n = lua_gettop(L) - 1;
        for (int k = 0; k < n/3; ++k)
        {
            int i = luaL_checkinteger(L, k * 3 + 2) - 1;
            unsigned int color = luaL_checkinteger(L, k * 3 + 3);
            float alpha = luaL_checknumber(L, k * 3 + 4);

            mesh->setColor(i, color, alpha);
        }
    }

    return 0;
}
Example #2
0
int MeshBinder::setColor(lua_State *L)
{
    Binder binder(L);
    GMesh *mesh = static_cast<GMesh*>(binder.getInstance("Mesh", 1));

    int i = luaL_checkinteger(L, 2) - 1;
    unsigned int color = luaL_checkinteger(L, 3);
    float alpha = luaL_optnumber(L, 4, 1.0);

    mesh->setColor(i, color, alpha);

    return 0;
}