示例#1
0
文件: Full.cpp 项目: staylo/XCSoar
lua_State *
Lua::NewFullState()
{
  lua_State *L = NewBasicState();

  InitLog(L);
  InitPersistent(L);
  InitTimer(L);
  InitMap(L);
  InitBlackboard(L);
  InitDialogs(L);
  InitLegacy(L);
  InitAirspace(L);
  InitTask(L);
  InitSettings(L);
  InitWind(L);
  InitLogger(L);
  InitTracking(L);
  InitReplay(L);
  InitInputEvent(L);

  {
    SetPackagePath(L,
                   WideToUTF8Converter(LocalPath(_T("lua" DIR_SEPARATOR_S "?.lua")).c_str()));
  }

  return L;
}
示例#2
0
static int
l_GeoPoint_tostring(lua_State *L)
{
  auto gp = Lua::ToGeoPoint(L, 1);
  Lua::Push(L, WideToUTF8Converter(FormatGeoPoint(gp, CoordinateFormat::DDMMSS)));
  return 1;
}
示例#3
0
文件: Request.cpp 项目: Advi42/XCSoar
Net::Request::Request(Session &_session, ResponseHandler &_handler,
                      const char *url)
  :session(_session), handler(_handler)
{
  char user_agent[32];
  snprintf(user_agent, 32, "XCSoar/%s",
           (const char *)WideToUTF8Converter(XCSoar_Version));

  handle.SetUserAgent(user_agent);
  handle.SetFailOnError(true);
  handle.SetWriteFunction(WriteCallback, this);

  handle.SetURL(url);

  session.Add(handle.GetHandle());
}
示例#4
0
static TextCache::Result
RenderText(const Font *font, const TCHAR *text)
{
  if (font == nullptr)
    return TextCache::Result::Null();

  assert(font->IsDefined());

#ifdef USE_FREETYPE
#ifdef UNICODE
  return TextCache::Get(*font, WideToUTF8Converter(text));
#else
  return TextCache::Get(*font, text);
#endif
#endif
}
示例#5
0
lua_State *
Lua::NewBasicState()
{
  lua_State *L = luaL_newstate();

  SetRegistry(L, "LUA_NOENV", true);

  for (auto l : loadedlibs) {
    luaL_requiref(L, l.name, l.func, 1);
    lua_pop(L, 1);
  }

  /* create the "xcsoar" namespace */
  lua_newtable(L);

  SetField(L, -2, "VERSION", WideToUTF8Converter(XCSoar_Version));

  lua_setglobal(L, "xcsoar");

  return L;
}
示例#6
0
bool
DeviceDescriptor::DoOpen(OperationEnvironment &env)
{
  assert(config.IsAvailable());

  {
    ScopeLock protect(mutex);
    error_message.clear();
  }

  if (config.port_type == DeviceConfig::PortType::INTERNAL)
    return OpenInternalSensors();

  if (config.port_type == DeviceConfig::PortType::DROIDSOAR_V2)
    return OpenDroidSoarV2();

  if (config.port_type == DeviceConfig::PortType::I2CPRESSURESENSOR)
    return OpenI2Cbaro();

  if (config.port_type == DeviceConfig::PortType::NUNCHUCK)
    return OpenNunchuck();

  if (config.port_type == DeviceConfig::PortType::IOIOVOLTAGE)
    return OpenVoltage();

  reopen_clock.Update();

  Port *port;
  try {
    port = OpenPort(io_service, config, this, *this);
  } catch (const std::runtime_error &e) {
    TCHAR name_buffer[64];
    const TCHAR *name = config.GetPortName(name_buffer, 64);

    LogError(WideToUTF8Converter(name), e);

    StaticString<256> msg;

    const UTF8ToWideConverter what(e.what());
    if (what.IsValid()) {
      ScopeLock protect(mutex);
      error_message = what;
    }

    msg.Format(_T("%s: %s (%s)"), _("Unable to open port"), name,
               (const TCHAR *)what);

    env.SetErrorMessage(msg);
    return false;
  }

  if (port == nullptr) {
    TCHAR name_buffer[64];
    const TCHAR *name = config.GetPortName(name_buffer, 64);

    StaticString<256> msg;
    msg.Format(_T("%s: %s."), _("Unable to open port"), name);
    env.SetErrorMessage(msg);
    return false;
  }

  DumpPort *dump_port = new DumpPort(port);
  dump_port->Disable();

  if (!port->WaitConnected(env) || !OpenOnPort(dump_port, env)) {
    if (!env.IsCancelled())
      ++n_failures;

    delete dump_port;
    return false;
  }

  ResetFailureCounter();
  return true;
}