示例#1
0
void LuaEngine::luaPush(const QVariant& variant)
{
	switch (variant.type())
	{
	case QVariant::Bool:
	{
		luaPush(variant.toBool());
		break;
	}
	case QVariant::String:
	{
		luaPush(variant.toString());
		break;
	}
	case QVariant::Int:
	{
		luaPush(variant.toInt());
		break;
	}
	case QVariant::Map:
	{
		luaPush(variant.toMap());
		break;
	}
	case QVariant::Hash:
	{
		luaPush(variant.toHash());
		break;
	}
	default:
		break;
	}
}
示例#2
0
void LuaEngine::luaPush(const QMap<QString, QVariant>& hash)
{
	lua_newtable(L);
	for (QMap<QString, QVariant>::const_iterator it = hash.constBegin(); it != hash.constEnd(); ++it)
	{
		luaPush(it.key());
		luaPush(it.value());
		lua_settable(L, -3);
	}
}
示例#3
0
文件: LuaUtils.cpp 项目: 0wu/fblualib
int defaultStdFunctionWrapper(lua_State* L, LuaStdFunction& fn) {
  try {
    return fn(L);
  } catch  (const std::exception& e) {
    luaPush(L, folly::exceptionStr(e));
    lua_error(L);
    return 0;  // unreached
  }
}
示例#4
0
int TestObject::luaIndex(lua_State* L) {
  auto arg = luaGet<folly::StringPiece>(L, 2);
  if (arg && *arg == "y") {
    luaPush(L, y);
  } else {
    lua_pushnil(L);
  }
  return 1;
}
示例#5
0
QVariant LuaEngine::invokeFunction(const char* object, const char* method, const QVariantList& arguments /*= QVariantList()*/, QLSCallback callback /*= nullptr*/)
{
	int argc = arguments.count();
#ifdef Q_OS_WIN
	foreach(const QVariant & argv, arguments)
#else
	for (const QVariant & argv : arguments)
#endif
	{
		luaPush(argv);
	}

	invokeFunction(std::string(object), std::string(method), argc, 1, callback != nullptr);

	QVariant result;

	if (lua_isnumber(L, -1))
	{
		result = luaPopNumber();
	}
	else if (lua_isstring(L, -1))
	{
		result = QString(luaPopString().c_str());
	}
	else if (lua_isuserdata(L, -1))
	{
		result = (qulonglong)lua_touserdata(L, -1);
	}
	else if (lua_istable(L, -1))
	{
		QHash<QString, QVariant> table;
		lua_pushnil(L);
		while (lua_next(L, -2) != 0)
		{
			table[lua_tostring(L, -2)] = lua_tostring(L, -1);
			lua_pop(L, 1);
		}
		lua_pop(L, 1); // remove table

		result = table;
	}

	return result;
}
示例#6
0
void LuaEngine::luaPush(const QString& string)
{
	luaPush(string.toStdString());
}
示例#7
0
int TestObject::luaValue(lua_State* L) {
  luaPush(L, x);
  return 1;
}
示例#8
0
int TestObject::luaLen(lua_State* L) {
  luaPush(L, 10);
  return 1;
}
示例#9
0
int TestObjectMethodsOnly::luaValue(lua_State* L) {
  luaPush(L, y);
  return 1;
}