Esempio n. 1
0
VALUE require_compiled(VALUE fname, VALUE* result)
{
    VALUE path;
    char* szName = 0;
//    FilePathValue(fname);

	szName = RSTRING_PTR(fname);
    RAWTRACE1("require_compiled: %s", szName);

    rb_funcall(fname, rb_intern("sub!"), 2, rb_str_new2(".rb"), rb_str_new2("") );

    if ( strcmp("strscan",szName)==0 || strcmp("enumerator",szName)==0 )
        return Qtrue;

    path = find_file(fname);

    if ( path != 0 )
    {
        VALUE seq;
		
        if ( isAlreadyLoaded(path) == Qtrue )
            return Qtrue;

        rb_ary_push(GET_VM()->loaded_features, path);

        seq = loadISeqFromFile(path);

        //*result = rb_funcall(seq, rb_intern("eval"), 0 );
        *result = rb_iseq_eval(seq);

        return Qtrue;
    }

    return Qnil;
}
Esempio n. 2
0
bool Plugin::loadPlugin(const wchar_t* fname)
{
    if (isAlreadyLoaded(fname))
        return false;
    const wchar_t *e = wcsrchr(fname, L'.');
    if (!e) return false;
    bool result = false;
    tstring ext(e+1);
    if (ext == L"lua") 
        result = loadLuaPlugin(fname);
    else if (ext == L"dll")
        result = loadDllPlugin(fname);
    current_state = false;
    load_state = result;
    return result;
}
Esempio n. 3
0
VALUE require_compiled(VALUE fname, VALUE* result)
{
    VALUE path;
    char* szName1 = 0;

    rb_funcall(fname, rb_intern("sub!"), 2, rb_str_new2(".rb"), rb_str_new2("") );

    szName1 = RSTRING_PTR(fname);
    if ( strcmp("strscan",szName1)==0 || strcmp("enumerator",szName1)==0 ||
        strcmp("stringio",szName1)==0 || strcmp("socket",szName1)==0 ||
        strcmp("digest.so",szName1)==0 || strcmp("openssl.so",szName1)==0 ||
        strcmp("fcntl",szName1)==0 || strcmp("digest/md5",szName1)==0 ||
        strcmp("digest/sha1",szName1)==0 )
        return Qtrue;

    if ( isAlreadyLoaded(fname) == Qtrue )
        return Qtrue;

    //RAWLOG_INFO1("find_file: %s", RSTRING_PTR(fname));
    path = find_file(fname);

    if ( path != 0 )
    {
        VALUE seq;

//        if ( isAlreadyLoaded(path) == Qtrue )
//            return Qtrue;

        RAWLOG_INFO1("require_compiled: %s", szName1);

        //optimize require
        //rb_ary_push(GET_VM()->loaded_features, path);
        rb_ary_push(GET_VM()->loaded_features, fname);

        rb_gc_disable();
        seq = loadISeqFromFile(path);
        rb_gc_enable();

        //*result = rb_funcall(seq, rb_intern("eval"), 0 );
        *result = rb_iseq_eval(seq);

        return Qtrue;
    }

    RAWLOG_ERROR1("require_compiled: error: can not find %s", RSTRING_PTR(fname));
    return Qnil;
}
Esempio n. 4
0
 bool MapTree::loadMap(const std::string& pDirFileName, unsigned int pMapTileIdent)
 {
     bool result = true;
     if(!hasDirFile(pDirFileName))
     {
         FilesInDir filesInDir;
         result = false;
         std::string fb = iBasePath + pDirFileName;
         FILE* df = fopen(fb.c_str(), "rb");
         if(df)
         {
             char lineBuffer[FILENAMEBUFFER_SIZE];
             result = true;
             bool newModelLoaded = false;
             while(result && (fgets(lineBuffer, FILENAMEBUFFER_SIZE-1, df) != 0))
             {
                 std::string name = std::string(lineBuffer);
                 chomp(name);
                 if(name.length() >1)
                 {
                     filesInDir.append(name);
                     ManagedModelContainer *mc;
                     if(!isAlreadyLoaded(name))
                     {
                         std::string fname = iBasePath;
                         fname.append(name);
                         mc = new ManagedModelContainer();
                         result = mc->readFile(fname.c_str());
                         if(result)
                         {
                             addModelContainer(name, mc);
                             newModelLoaded = true;
                         }
                     }
                     else
                     {
                         mc = getModelContainer(name);
                     }
                     mc->incRefCount();
                 }
             }
             if(result && newModelLoaded)
             {
                 iTree->balance();
             }
             if(result && ferror(df) != 0)
             {
                 result = false;
             }
             fclose(df);
             if(result)
             {
                 filesInDir.incRefCount();
                 addDirFile(pDirFileName, filesInDir);
                 setLoadedMapTile(pMapTileIdent);
             }
         }
     }
     else
     {
         // Already loaded, so just inc. the ref count if mapTileIdent is new
         if(!containsLoadedMapTile(pMapTileIdent))
         {
             setLoadedMapTile(pMapTileIdent);
             FilesInDir& filesInDir = getDirFiles(pDirFileName);
             filesInDir.incRefCount();
         }
     }
     return (result);
 }
Esempio n. 5
0
VALUE require_compiled(VALUE fname, VALUE* result, int bLoad)
{
    VALUE path;
    char* szName1 = 0;
    VALUE retval = Qtrue;
    
    if (TYPE(fname) != T_STRING)
        rb_raise(rb_eLoadError, "can not load non-string");

    szName1 = RSTRING_PTR(fname);

    if ( String_endsWith(szName1,".rb") ) 
    {
        rb_str_chop_bang(fname); rb_str_chop_bang(fname); rb_str_chop_bang(fname);
    }
    //rb_funcall(fname, rb_intern("sub!"), 2, rb_str_new2(".rb"), rb_str_new2("") );
    szName1 = RSTRING_PTR(fname);

    if ( strcmp("strscan",szName1)==0 || strcmp("enumerator",szName1)==0 ||
        strcmp("stringio",szName1)==0 || strcmp("socket",szName1)==0 )
        return Qtrue;

    RHO_LOCK(require_lock);

    if ( !bLoad && isAlreadyLoaded(fname) == Qtrue )
        goto RCompExit;

    path = find_file(fname);

    if ( path != 0 )
    {
        VALUE seq;

        RAWLOG_INFO1("require_compiled: %s", szName1);

        //optimize require
        //rb_ary_push(GET_VM()->loaded_features, path);
        rb_ary_push(GET_VM()->loaded_features, fname);

#ifdef RHODES_EMULATOR
        if ( strstr( RSTRING_PTR(path), ".rb") == 0 )
            rb_str_cat(path,".rb",3);

        GET_VM()->src_encoding_index = rb_utf8_encindex();
        rb_load(path, 0);

        if( rho_simconf_getBool("reload_app_changes") )
        {
            if ( strncmp( RSTRING_PTR(path), rho_native_rhopath(), strlen(rho_native_rhopath()) ) == 0 )
                rb_ary_delete(GET_VM()->loaded_features, fname);
        }
#else
        //rb_gc_disable();
        seq = loadISeqFromFile(path);
        

        //*result = rb_funcall(seq, rb_intern("eval"), 0 );
        *result = rb_iseq_eval(seq);
        
        //rb_gc_enable();
#endif
        goto RCompExit;
    }

    RAWLOG_ERROR1("require_compiled: error: can not find %s", RSTRING_PTR(fname));
    retval = Qnil;

RCompExit:
    RHO_UNLOCK(require_lock);
    return retval;
}