Пример #1
1
//
// Printer
//
void Printer::PrintTable(std::string *result, Sqrat::Table table) {
	result->append("{");

	int i = 0;
	Sqrat::Table::iterator it;
	while (table.Next(it)) {
		if (i > 0) {
			result->append(",");
		}
		result->append("[\"");
		Sqrat::Object o(it.getKey(), table.GetVM());
		result->append(o.Cast<std::string>());
		result->append("\"]=");
		Sqrat::Object obj(it.getValue(), table.GetVM());
		PrintValue(result, obj);
		i++;
	}

	result->append("}");
}
Пример #2
0
void JsonPrinter::PrintTable(Json::Value &value, Sqrat::Table table) {
	Sqrat::Table::iterator it;
	while(table.Next(it)) {
		Sqrat::Object o(it.getKey(), table.GetVM());
		std::string key = o.Cast<std::string>();
		Sqrat::Object obj(it.getValue(), table.GetVM());
		value[key] = PrintValue(obj);
	}
}
Пример #3
0
bool GameWorld::copyParameterTable(const Sqrat::Table &in, Sqrat::Table &out) {
  sq::Object::iterator it;
  while (in.Next(it)) {
    sq::Object value = in.GetSlot(it.getName());
    switch (value.GetType()) {
      case OT_NULL:
      {
        out.SetValue(it.getName(), nullptr);
      }
        break;
      case OT_BOOL:
      {
        out.SetValue(it.getName(), value.Cast<bool>());
      }
        break;
      case OT_INTEGER:
      {
        out.SetValue(it.getName(), value.Cast<int>());
      }
        break;
      case OT_FLOAT:
      {
        out.SetValue(it.getName(), value.Cast<float>());
      }
        break;
      case OT_STRING:
      {
        out.SetValue(it.getName(), value.Cast<std::string>());
      }
        break;
      default:
        std::cout<<"Attemt to pass unsafe parameter to game world";
    }
  }
  return true;
}