Changeset 190

Show
Ignore:
Timestamp:
08/13/07 14:45:59 (1 year ago)
Author:
JarrettBillingsley
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/minid/baselib.d

    r183 r190  
    410410        globals["setModuleLoader"d] = new MDClosure(globals.ns, &lib.setModuleLoader,       "setModuleLoader"); 
    411411        globals["removeKey"d] =       new MDClosure(globals.ns, &lib.removeKey,             "removeKey"); 
     412        globals["bindContext"d] =     new MDClosure(globals.ns, &lib.bindContext,           "bindContext"); 
    412413 
    413414        MDNamespace namespace = new MDNamespace("namespace"d, globals.ns); 
     
    831832        return s.call(funcReg, numParams + 2, -1); 
    832833    } 
    833      
     834 
    834835    int curry(MDState s, uint numParams) 
    835836    { 
     
    839840         
    840841        s.push(new MDClosure(upvalues[0].as!(MDClosure).environment, &curryClosure, "curryClosure", upvalues)); 
     842        return 1; 
     843    } 
     844     
     845    int bindContext(MDState s, uint numParams) 
     846    { 
     847        struct Closure 
     848        { 
     849            MDClosure func; 
     850            MDValue context; 
     851 
     852            int call(MDState s, uint numParams) 
     853            { 
     854                uint funcReg = s.push(func); 
     855                s.push(context); 
     856 
     857                for(uint i = 0; i < numParams; i++) 
     858                    s.push(s.getParam(i)); 
     859 
     860                return s.call(funcReg, numParams + 1, -1); 
     861            } 
     862        } 
     863 
     864        auto cl = new Closure; 
     865        cl.func = s.getParam!(MDClosure)(0); 
     866        cl.context = s.getParam(1u); 
     867 
     868        s.push(new MDClosure(cl.func.environment, &cl.call, "bound function")); 
    841869        return 1; 
    842870    }