示例#1
0
		void LuaTable::fromLua(LuaState& lua) {
			
			std::for_each(std::begin(intKeys), std::end(intKeys),
				[&](std::pair<const int, unsigned> intKey)->void {

				int x = 0;

				lua.getTable(intKey.first);

				pullAnyValue(lua, types[intKey.second], values[intKey.second]);

				lua.popStack();

			});

			std::for_each(std::begin(stringKeys), std::end(stringKeys),
				[&](std::pair<const std::string, unsigned> stringKey)->void {

				lua.getTable(stringKey.first);

				pullAnyValue(lua, types[stringKey.second], values[stringKey.second]);

				lua.popStack();

			});

		}
示例#2
0
bool TestLua::testSimple() {
    LuaState lua;
    assert(lua.getLua() != NULL);

    int ref = lua.newTable("table1");
    lua.setTableValue("name", "Melli");
    lua.setTableValue("age", 22);

    lua.pop(1);

    assert(!lua_istable(lua, -1));
    lua.getTable("table1");
    assert(lua_istable(lua, -1));

    lua.pop(1);
    assert(!lua_istable(lua, -1));
    lua.getTable(ref);
    assert(lua_istable(lua, -1));

    const char *name = lua.getTableString("name");
    assert(name != NULL);
    am_equalsStr("Melli", name);
    int age = 0;
    assert(lua.getTableInt("age", age));
    am_equals(22, age);
    name = lua.getTableString("name");
    assert(name != NULL);
    am_equalsStr("Melli", name);

    lua.pop(1);

    am_equals(0, lua_gettop(lua));

    lua.close();

    return true;
}