Ejemplo n.º 1
0
		void LuaTable::toLua(LuaState& lua) const {
			lua.createTable(intKeys.size(), stringKeys.size());

			std::for_each(std::begin(intKeys), std::end(intKeys),
				[&](std::pair<const int, unsigned> intKey)->void {

				lua.pushStack(intKey.first);

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

				lua.setTable();

			});

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

				lua.pushStack(stringKey.first);

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

				lua.setTable();

			});

		}
Ejemplo n.º 2
0
		void LuaTable::pushAnyValue(LuaState& lua, std::type_index type, void* value) const {

			 if (type == typeid(int)) {
				lua.pushStack(*static_cast<int*>(value));
			}
			else if (type == typeid(std::string)) {
				lua.pushStack(*static_cast<std::string*>(value));
			}
			else if (type == typeid(long)) {
				lua.pushStack(*static_cast<long*>(value));
			}
			else if (type == typeid(bool)) {
				lua.pushStack(*static_cast<bool*>(value));
			}
			else if (type == typeid(float)) {
				lua.pushStack(*static_cast<float*>(value));
			}
			else if (type == typeid(double)) {
				lua.pushStack(*static_cast<double*>(value));
			}
			else if (type == typeid(LuaFunction)) {
				lua.pushStack(*static_cast<LuaFunction*>(value));
			}
			else {
				auto vcast = static_cast<LuaTable*>(value);
				vcast->toLua(lua);
			}

		}