コード例 #1
0
ファイル: LuaGrid.cpp プロジェクト: Action-Committee/pioneer
	static int l_set_cell(lua_State *l) {
		UI::Grid *g = LuaObject<UI::Grid>::CheckFromLua(1);
		UI::Context *c = g->GetContext();

		size_t colNum = luaL_checkinteger(l, 2);
		size_t rowNum = luaL_checkinteger(l, 3);
		UI::Widget *w = UI::Lua::CheckWidget(c, l, 4);

		if (colNum >= g->GetNumCols()) {
			luaL_error(l, "no such column %d (max is %d)", colNum, g->GetNumCols()-1);
			return 0;
		}
		if (rowNum >= g->GetNumRows()) {
			luaL_error(l, "no such row %d (max is %d)", rowNum, g->GetNumRows()-1);
			return 0;
		}

		g->SetCell(colNum, rowNum, w);

		lua_pushvalue(l, 1);
		return 1;
	}
コード例 #2
0
ファイル: LuaGrid.cpp プロジェクト: Action-Committee/pioneer
	static int l_set_column(lua_State *l) {
		UI::Grid *g = LuaObject<UI::Grid>::CheckFromLua(1);
		UI::Context *c = g->GetContext();

		size_t colNum = luaL_checkinteger(l, 2);
		luaL_checktype(l, 3, LUA_TTABLE);

		if (colNum >= g->GetNumCols()) {
			luaL_error(l, "no such column %d (max is %d)", colNum, g->GetNumCols()-1);
			return 0;
		}

		for (size_t i = 0; i < g->GetNumRows() && i < lua_rawlen(l, 3); i++) {
			lua_rawgeti(l, 3, i+1);
			if (lua_isnil(l, -1))
				g->ClearCell(colNum, i);
			else
				g->SetCell(colNum, i, UI::Lua::CheckWidget(c, l, -1));
			lua_pop(l, 1);
		}

		lua_pushvalue(l, 1);
		return 1;
	}