Ejemplo n.º 1
0
static int lua_lstyle_new (lua_State *L) {

	size_t st;
	const char* name = luaL_checklstring(L, 2, &st);
	Color* color = lua_checkcolor(L, 3);
	double font_size = luaL_optnumber(L, 4, 1.0);

	Style** c = static_cast<Style**>(lua_newuserdata(L, sizeof(Style*)));
	luaL_getmetatable(L, "layout_style");
	lua_setmetatable(L, -2);

	Style *e = new Style(name, color, font_size);
	*c = static_cast<Style*>(e);

	return 1;
}
Ejemplo n.º 2
0
int luaNode__newindex(lua_State* l) {
    is::Node* node = lua_tonode(l,1);
    if ( node == NULL ) {
        lua_Debug ar1;
        lua_getstack( l, 1, &ar1 );
        lua_getinfo( l, "fl", &ar1 );
        lua_Debug ar2;
        lua_getinfo( l, ">S", &ar2 );
        lua_pushfstring( l, "%s:%d: attempt to index a NULL Node!", ar2.short_src, ar1.currentline );
        return lua_error( l );
    }
    std::string field = luaL_checkstring(l,2);
    if ( field == "pos" ) {
        node->setPos( *lua_checkvector( l, 3 ) );
    } else if ( field == "ang" ) {
        node->setAng( *lua_checkvector( l, 3 ) );
    } else if ( field == "scale" ) {
        node->setScale( *lua_checkvector( l, 3 ) );
    } else if ( field == "color" ) {
        node->setColor( *lua_checkcolor( l, 3 ) );
    } else if ( field == "x" ) {
        glm::vec3 pos = node->getPos();
        pos.x = luaL_checknumber( l, 3 );
        node->setPos( pos );
    } else if ( field == "y" ) {
        glm::vec3 pos = node->getPos();
        pos.y = luaL_checknumber( l, 3 );
        node->setPos( pos );
    } else if ( field == "z" ) {
        glm::vec3 pos = node->getPos();
        pos.z = luaL_checknumber( l, 3 );
        node->setPos( pos );
    } else if ( field == "sx" ) {
        glm::vec3 scale = node->getScale();
        scale.x = luaL_checknumber( l, 3 );
        node->setScale( scale );
    } else if ( field == "sy" ) {
        glm::vec3 scale = node->getScale();
        scale.y = luaL_checknumber( l, 3 );
        node->setScale( scale );
    } else if ( field == "sz" ) {
        glm::vec3 scale = node->getScale();
        scale.z = luaL_checknumber( l, 3 );
        node->setScale( scale );
    } else if ( field == "r" ) {
        glm::vec4 color = node->getColor();
        color.x = luaL_checknumber( l, 3 );
        node->setColor( color );
    } else if ( field == "g" ) {
        glm::vec4 color = node->getColor();
        color.y = luaL_checknumber( l, 3 );
        node->setColor( color );
    } else if ( field == "b" ) {
        glm::vec4 color = node->getColor();
        color.z = luaL_checknumber( l, 3 );
        node->setColor( color );
    } else if ( field == "a" ) {
        glm::vec4 color = node->getColor();
        color.w = luaL_checknumber( l, 3 );
        node->setColor( color );
    } else {
        luaText__newindex( l );
        luaButton__newindex( l );
        luaCheckbox__newindex( l );
        luaDropdown__newindex( l );
        if ( node->m_luaReference == LUA_NOREF ) {
            lua_newtable( l );
            node->m_luaReference = luaL_ref( l, LUA_REGISTRYINDEX );
        }
        lua_rawgeti( l, LUA_REGISTRYINDEX, node->m_luaReference );
        lua_pushvalue( l, 3 );
        lua_setfield( l, -2, luaL_checkstring( l, 2 ) );
    }

    return 0;
}