当前位置: 首页>>代码示例>>C++>>正文


C++ LuaState::push方法代码示例

本文整理汇总了C++中LuaState::push方法的典型用法代码示例。如果您正苦于以下问题:C++ LuaState::push方法的具体用法?C++ LuaState::push怎么用?C++ LuaState::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LuaState的用法示例。


在下文中一共展示了LuaState::push方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testSimple

	bool TestLuaTileSet::testSimple() {
		LuaState lua;
		
		assert(lua.loadString("TileSet = import(\"TileSet\")\n"
			"set = TileSet.new(\"testTileSet\")\n"
			"function getName()\n"
			"	return set:name()\n"
			"end\n"
			"function getFullName()\n"
			"	return set:full_name()\n"
			"end\n"
			"function setFullName(name)\n"
			"	set:full_name(name)\n"
			"end\n"
			));

		assert(lua.hasGlobalFunction("getName"));
		lua_acall(lua, 0, 1);
		am_equalsStr("testTileSet", lua_tostring(lua, -1));
		lua.pop(1);

		assert(lua.hasGlobalFunction("setFullName"));
		lua.push("New Full Name");
		lua_acall(lua, 1, 0);
		
		assert(lua.hasGlobalFunction("getFullName"));
		lua_acall(lua, 0, 1);
		am_equalsStr("New Full Name", lua_tostring(lua, -1));
		lua.pop(1);

		return true;
	}
开发者ID:astrellon,项目名称:GPP,代码行数:32,代码来源:test_lua_tile_set.cpp

示例2: testTiles

	bool TestLuaTileSet::testTiles() {
		LuaState lua;
		
		assert(lua.loadString("TileSet = import(\"TileSet\")\n"
			"Tile = import(\"Tile\")\n"
			"set = TileSet.new(\"testTileSet\")\n"
			"function addTile(tile)\n"
			"	set:add_tile(tile)\n"
			"end\n"
			"function removeTile(tile)\n"
			"	set:remove_tile(tile)\n"
			"end\n"
			"function getTile(tileName)\n"
			"	return set:tile(tileName)\n"
			"end\n"
			"function hasTile(tile)\n"
			"	return set:has_tile(tile)\n"
			"end\n"
			));

		assert(lua.hasGlobalFunction("hasTile"));
		lua.push("myTile");
		lua_acall(lua, 1, 1);
		assert(!lua_toboolean(lua, -1));
		lua.pop(1);

		Tile *tile = new Tile("myTile");

		assert(lua.hasGlobalFunction("addTile"));
		wrapRefObject<Tile>(lua, tile);
		lua_acall(lua, 1, 0);

		assert(lua.hasGlobalFunction("hasTile"));
		lua.push("myTile");
		lua_acall(lua, 1, 1);
		assert(lua_toboolean(lua, -1));
		lua.pop(1);
		
		assert(lua.hasGlobalFunction("hasTile"));
		wrapRefObject<Tile>(lua, tile);
		lua_acall(lua, 1, 1);
		assert(lua_toboolean(lua, -1));
		lua.pop(1);

		assert(lua.hasGlobalFunction("getTile"));
		lua.push("myTile");
		lua_acall(lua, 1, 1);
		lua_getmetatable(lua, -1);
		Tile *get = castUData<Tile>(lua, 1);
		lua.pop(1);
		assert(tile == get);

		assert(lua.hasGlobalFunction("removeTile"));
		lua.push("myTile");
		lua_acall(lua, 1, 0);

		assert(lua.hasGlobalFunction("hasTile"));
		lua.push("myTile");
		lua_acall(lua, 1, 1);
		assert(!lua_toboolean(lua, -1));
		lua.pop(1);

		return true;
	}
开发者ID:astrellon,项目名称:GPP,代码行数:64,代码来源:test_lua_tile_set.cpp

示例3: testScripts

bool TestLua::testScripts()
{
    LuaState lua;
    lua.loadString("function testFunc(x, y)\n"
                   "	return x * y\n"
                   "end");

    assert(lua.hasGlobalFunction("testFunc"));
    lua.push(4);
    lua.push(5);
    lua_acall(lua, 2, 1);
    int result = lua_tointeger(lua, -1);
    am_equals(20, result);
    lua.pop(1);

    am_equals(0, lua_gettop(lua));
    assert(!lua.hasGlobalFunction("notafunc"));
    am_equals(0, lua_gettop(lua));

    assert(lua.loadString("function notafunc()\n"
                          "	return \"hello there\"\n"
                          "end"));

    assert(lua.hasGlobalFunction("testFunc"));
    lua.push(4);
    lua.push(5);
    lua_acall(lua, 2, 1);
    result = lua_tointeger(lua, -1);
    am_equals(20, result);
    lua.pop(1);

    am_equals(0, lua_gettop(lua));
    assert(lua.hasGlobalFunction("notafunc"));
    am_equals(1, lua_gettop(lua));

    lua_acall(lua, 0, 1);
    const char *callResult = lua_tostring(lua, -1);
    am_equalsStr(callResult, "hello there");
    lua.pop(1);
    am_equals(0, lua_gettop(lua));

    // You can redefine functions!
    // And load them at run-time!
    // Must find a way of making use of this.
    assert(lua.loadString("function notafunc()\n"
                          "	return \"how are you?\"\n"
                          "end"));

    am_equals(0, lua_gettop(lua));
    assert(lua.hasGlobalFunction("notafunc"));
    am_equals(1, lua_gettop(lua));

    lua_acall(lua, 0, 1);
    callResult = lua_tostring(lua, -1);
    am_equalsStr(callResult, "how are you?");
    lua.pop(1);
    am_equals(0, lua_gettop(lua));

    lua.close();

    return true;
}
开发者ID:astrellon,项目名称:GPP,代码行数:62,代码来源:test_lua.cpp


注:本文中的LuaState::push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。