Example #1
0
int Start(char* src) {
  if (!InitJerry()) {
    DLOG("InitJerry failed");
    return 1;
  }

  JObject* process = InitModules();

  // FIXME: this should be moved to seperate function
  {
    JObject argv;
    argv.SetProperty("1", JObject(src));
    process->SetProperty("argv", argv);
  }

  if (!StartIoTjs(process)) {
    DLOG("StartIoTJs failed");
    return 1;
  }

  CleanupModules();

  ReleaseJerry();

  return 0;
}
Example #2
0
JObject* InitTcp() {
  Module* module = GetBuiltinModule(MODULE_TCP);
  JObject* tcp = module->module;

  if (tcp == NULL) {
    tcp = new JObject(TCP);

    JObject prototype;
    tcp->SetProperty("prototype", prototype);

    prototype.SetMethod("open", Open);
    prototype.SetMethod("close", Close);
    prototype.SetMethod("connect", Connect);
    prototype.SetMethod("bind", Bind);
    prototype.SetMethod("listen", Listen);
    prototype.SetMethod("write", Write);
    prototype.SetMethod("readStart", ReadStart);
    prototype.SetMethod("shutdown", Shutdown);
    prototype.SetMethod("setKeepAlive", SetKeepAlive);

    module->module = tcp;
  }

  return tcp;
}
Example #3
0
int JLuaServer::FnSet( lua_State* pLua )
{
    if (lua_gettop( pLua ) < 3 || lua_gettop( pLua ) > 4)
    {
        rlog.err( "LUA: Incorrect command usage: <set>. "
            "Function takes 3 or 4 arguments (<objectRef>|<objectName>, <propName>, <val>, [tag]), but %d is provided", 
            lua_gettop( pLua ) );
        lua_settop( pLua, 0 );
        lua_pushnil( pLua );
        return 1;
    }
    JObject* pObj = NULL;
    const char* pPath = lua_tostring( pLua, 1 );
    if (pPath)
    {
        JLuaThread* pThread = reinterpret_cast<JLuaThread*>( pLua->userdata );
        assert( pThread->m_pLua == pLua );
        JObject* pRootObj = pThread->m_pRootObj;
        pObj = g_pObjectServer->FindObject( pPath, NULL, pRootObj );
    }
    else
    {
        pObj = reinterpret_cast<JObject*>( lua_touserdata( pLua, 1 ) );
    }
    const char* pPropName = lua_tostring( pLua, 2 );
    const char* pPropVal  = lua_tostring( pLua, 3 );

    if (!pPropVal && lua_isboolean( pLua, 3 ))
    {
        bool bVal = lua_toboolean( pLua, 3 ) == 0 ? false : true;
        pPropVal = bVal ? "true" : "false";
    }

    int tag = -1;
    if (lua_isnumber( pLua, 4 ))
    {
        tag = (int)lua_tonumber( pLua, 4 );
    }

    if (!pObj)
    {
        rlog.warn( "LUA: Trying to call <set> for the nil object." );
        return 0;
    }

    bool bRes = pObj->SetProperty( pPropName, pPropVal, tag );
    if (!bRes)
    {
        rlog.err( "LUA: Could not set property '%s' for object '%s' of type '%s'.", 
            pPropName, pObj->GetName(), pObj->ClassName() );
    }

    return 0;
} // JLuaServer::FnSet
Example #4
0
void JStringServer::ExtractStrings()
{
    FILE* fp = fopen( "strings.txt", "wt" );
    if (!fp)
    {
        return;
    }
    m_Dictionary.clear();

    //  extract text strings
    JObjectIterator it( JCore::s_pInstance );
    JString val, hash;
    while (it)
    {
        JObject* pObj = *it;
        if (pObj->HasName( "system" ))
        {
            it.breadth_next();
            continue;
        }
        ++it;
        bool bRes = pObj->GetProperty( "text", val );
        if (!bRes || val.size() == 0 || val[0] == '#')
        {
            continue;
        }
        if (!HasCyrillics( val.c_str() ))
        {
            continue;
        }
        HashString( val.c_str(), hash );
        JStringDictionary::iterator location = m_Dictionary.find( hash );

        JString taggedHash = "#";
        taggedHash += hash;
        pObj->SetProperty( "text", taggedHash.c_str() );

        if (location != m_Dictionary.end())
        {
            if (val == (*location).second)
            {
                continue;
            }
            assert( false );
        }
        fprintf( fp, "%s %s\n", hash.c_str(), val.c_str() );
        m_Dictionary[hash] = val;
    }
    fclose( fp );

    //  save scripts
    g_pPersistServer->SaveScripts();
}
JObject* InitBuffer() {
  Module* module = GetBuiltinModule(MODULE_BUFFER);
  JObject* buffer = module->module;

  if (buffer == NULL) {
    buffer = new JObject(Buffer);

    JObject prototype;
    buffer->SetProperty("prototype", prototype);

    prototype.SetMethod("compare", Compare);
    prototype.SetMethod("copy", Copy);
    prototype.SetMethod("write", Write);
    prototype.SetMethod("slice", Slice);
    prototype.SetMethod("toString", ToString);

    module->module = buffer;
  }

  return buffer;
}