Changeset 72
- Timestamp:
- 07/28/06 17:10:49 (2 years ago)
- Files:
-
- branches/experimental/jsolait/jsolait.js (modified) (28 diffs)
- branches/experimental/jsolait/jsolait.wsf (modified) (2 diffs)
- branches/experimental/jsolait/lib/asyncimprt.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/experimental/jsolait/jsolait.js
r70 r72 30 30 **/ 31 31 32 jsolait=(function(){ 33 jsolait = {}; 34 35 jsolait.__name__='jsolait'; 36 37 jsolait.__version__="$Revision$"; 38 39 jsolait.__str__ =function(){ 32 jsolait=(function(publ){{with(publ){ 33 34 publ.__name__='jsolait'; 35 36 publ.__version__="$Revision$"; 37 38 publ.__str__ =function(){ 40 39 return "[module '%s' version: %s]".format(this.__name__, (this.__version__+'').replace(/\$Revision:\s(\d+) \$/, "Rev.$1")); 41 40 }; 42 jsolait.toString=jsolait.__str__;41 publ.toString=__str__; 43 42 44 43 ///The location where jsolait is installed. 45 44 //do not edit the following lines, it will be replaced by the build script 46 45 /*@baseURI begin*/ 47 jsolait.baseURI="./jsolait";46 publ.baseURI="./jsolait"; 48 47 /*@baseURI end*/ 49 48 … … 51 50 //do not edit the following lines, it will be replaced by the build script 52 51 /*@moduleSourceURIs begin*/ 53 jsolait.moduleSourceURIs={};52 publ.moduleSourceURIs={}; 54 53 /*@moduleSourceURIs end*/ 55 54 … … 59 58 they may contain StringFormating symbols e.g '%(baseURI)s/lib' 60 59 **/ 61 jsolait.moduleSearchURIs = [".", "%(baseURI)s/lib"];60 publ.moduleSearchURIs = [".", "%(baseURI)s/lib"]; 62 61 63 jsolait.packagesURI = "%(baseURI)s/packages"; 64 65 jsolait.modules={}; 62 publ.packagesURI = "%(baseURI)s/packages"; 63 64 publ.modules={}; 65 66 /** 67 Returns a string representation of an object. 68 @param obj The object to return a string repr. of. 69 @return A string repr. the object. 70 **/ 71 publ.str = String; 72 73 /** 74 Return a String containing a printable representation of an object which can be used with eval() to create an equal object. 75 Objects can cosutumize the the value being returned by repr(obj) by providing a obj.__repr__() method which is called by repr(obj). 76 @param obj The object to create a repr. String from. 77 @return A representation of the object. 78 **/ 79 publ.repr = function(obj){ 80 if(obj == null){ 81 return null; 82 }else if(obj.__repr__){ 83 return obj.__repr__(); 84 }else{ 85 switch(typeof obj){ 86 case "string": 87 obj = obj.replace(/\\/g,"\\\\").replace(/\"/g,"\\\"").replace(/\n/g, "\\n").replace(/\r/g,"\\r"); 88 return '"' + obj + '"'; 89 case "boolean":case"number": 90 return "" + obj; 91 case "object": 92 var out = []; 93 if(obj == null){ 94 return "null"; 95 }else if(obj instanceof Array){ 96 for(var i=0;i<obj.length;i++){ 97 out.push(repr(obj[i])); 98 } 99 return "[" + out.join(",") + "]"; 100 }else if(obj instanceof Object){ 101 for(var key in obj){ 102 out.push(repr(key) + ":" + repr(obj[key])); 103 } 104 return "{" + out.join(",") + "}"; 105 } 106 } 107 } 108 }; 109 110 /** 111 Returns a unique id for an object. 112 The same object will always return the same id. 113 Most objects are id-able. The following steps are taken to find an id. 114 If the obj has an __id__ property that id will be returned. (all jsolait classes have an __id__ property) 115 If the obj has a __id__ method the return value of that method will be returned.(all jsolait objects have a __id__ method which sets an __id__ property) 116 If the obj is a String the string prefixed with $ is returned. 117 If the obj is a Number the number prefixed with a # is returned as a string. 118 All other objects are not safely id-able and an exception is thrown unless forceId is true. In that case the object will get a unique __id__ property applied which is returned. 119 120 @param obj The object to get the id for. 121 @param forceId=false if true it forces id() to set an __id__ property onto a non id-able object, making it id-able. 122 @return A String containing a id value for the obj. 123 **/ 124 publ.id = function(obj, forceId){ 125 switch(typeof obj.__id__){ 126 127 case "undefined": 128 if(obj instanceof String || typeof obj == 'string'){ 129 return '$' + obj; 130 }else if(obj instanceof Number || typeof obj == 'number'){ 131 return '#' + obj; 132 }else if(forceId){ 133 obj.__id__ = '@' + (Class.__idcount__++); 134 return obj.__id__; 135 }else{ 136 throw new Exception('Objec cannot be IDed: %s'.format(obj)); 137 } 138 139 case "function": 140 return obj.__id__(); 141 142 default: //string 143 return obj.__id__; 144 } 145 }; 146 147 /** 148 Returns a bound method. 149 A bound method is a function which is bound to a specific object. 150 Calling the bound method will call the given function with the this-object inside that function's scope being the object specified. 151 152 @param obj The object the function should be bound to. 153 @param fn A function object the obj will be bound to. 154 @return A method which when run executes the function with the this-object being the obj specified. 155 **/ 156 publ.bind = function(obj, fn){ 157 return function(){ 158 return fn.apply(obj, arguments); 159 }; 160 }; 161 162 /** 163 Returns if an object is an instance of a specified class or of a direct or indirect subclass thereof. 164 165 It also works for traditional javascript inheritance(i.e. SomeClass=function(){}; SomeClass.prototype=new SuperClass(); ...). 166 Internaly it first checks using instanceof if that fails it uses isinstance(obj.constructor, cls). 167 There are some differences between using isinstance and instanceof. 168 i.e. 169 (123 instanceof Number) == false; 170 isinstance(123, Number) == true; 171 ('abc' instanceof String) == false; 172 isinstance('abc', String) == true; 173 174 @param obj The object to test. 175 @param cls The class to test against. 176 @return True if the object is an instance of cls. False otherwise. 177 **/ 178 publ.isinstance=function(obj, cls){ 179 if(obj instanceof cls){ 180 return true; 181 }else{ 182 return issubclass(obj.constructor, cls); 183 } 184 }; 185 186 /** 187 Returns if a cls is a direct or indirect subclass of another. 188 189 A class is always a subclass of itself and Object is the base for all classes. 190 A class is a subclass of baseclass if it's prototype is an instance of baseclass. 191 A class is a subclass of baseclass if any of it's __bases__ is a subclass of baseclass. 192 If there are no __bases__ defined there is no way to findout about inheritance besides 193 the prototype chain which was checked by instanceof before, so false is returned. 194 195 @param cls The class to test. 196 @param baseclass The assumed superclass. 197 @return True if cls is a subclass of baseclass otherwise false. 198 **/ 199 publ.issubclass=function(cls, baseclass){ 200 if(baseclass === Object || cls===baseclass || (cls.prototype instanceof baseclass)){ 201 return true; 202 }else{ 203 var bases = cls.__bases__; 204 if(bases != null){ 205 for(var i=0;i<bases.length;i++){ 206 if(bases[i] === baseclass){ 207 return true; 208 } 209 } 210 for(var i=0;i<bases.length;i++){ 211 if(issubclass(bases[i], baseclass)){ 212 return true; 213 } 214 } 215 } 216 return false; 217 } 218 }; 219 66 220 67 221 /** … … 76 230 the super class' wrapper for calling inherited methods. 77 231 **/ 78 varClass=function(name, base1, classScope){232 publ.Class=function(name, base1, classScope){ 79 233 var args=[]; 80 234 for(var i=0;i<arguments.length;i++){ … … 251 405 Class.__str__=Class.toString = function(){return "[object Class]";}; 252 406 Class.__createProto__=function(){ throw "Can't use Class as a base class.";}; 253 jsolait.Class = Class;254 407 255 408 Function.__createProto__ = function(){ throw "Cannot inherit from Function. implement the callable interface instead using YourClass::__call__.";}; … … 261 414 String.__str__ =String.toString=function(){return "[class String]";}; 262 415 263 jsolait.Exception=Class(function(publ){416 publ.Exception=Class(function(publ){ 264 417 /** 265 418 Initializes a new Exception. … … 302 455 publ.message; 303 456 ///The module the Exception belongs to. 304 publ.module= jsolait;457 publ.module=publ; 305 458 ///The error which caused the Exception or undefined. 306 459 publ.trace; 307 460 }); 308 461 309 jsolait.ModuleClass=Class(function(publ){462 publ.ModuleClass=Class(function(publ){ 310 463 publ.__name__; 311 464 publ.__version__; … … 330 483 @return HTTP request object. 331 484 **/ 332 jsolait.getHTTPRequestObject=function() {485 publ.getHTTPRequestObject=function() { 333 486 var obj; 334 487 try{ //to get the mozilla httprequest object … … 344 497 obj = new ActiveXObject("microsoft.XMLHTTP"); 345 498 }catch(e){ 346 throw new jsolait.Exception("Unable to get an HTTP request object.");499 throw new Exception("Unable to get an HTTP request object."); 347 500 } 348 501 } … … 355 508 Thrown when a file could not be loaded. 356 509 **/ 357 jsolait.LoadURIFailed=Class(jsolait.Exception, function(publ, priv,supr){510 publ.LoadURIFailed=Class(Exception, function(publ, priv,supr){ 358 511 /** 359 512 Initializes a new LoadURIFailed Exception. … … 376 529 @return The content of the file. 377 530 **/ 378 jsolait.loadURI=function(uri, headers){531 publ.loadURI=function(uri, headers){ 379 532 headers = (headers !== undefined) ? headers : []; 380 533 try{ 381 var xmlhttp = jsolait.getHTTPRequestObject();534 var xmlhttp = getHTTPRequestObject(); 382 535 xmlhttp.open("GET", uri, false); 383 536 for(var i=0;i< headers.length;i++){ … … 386 539 xmlhttp.send(""); 387 540 }catch(e){ 388 throw new jsolait.LoadURIFailed(uri, e);541 throw new LoadURIFailed(uri, e); 389 542 } 390 543 //todo: the status checking needs testing … … 393 546 return s; 394 547 }else{ 395 throw new jsolait.LoadURIFailed(uri, new jsolait.Exception("Server did not respond with status code 200 but with: " + xmlhttp.status)); 396 } 397 }; 398 548 throw new LoadURIFailed(uri, new Exception("Server did not respond with status code 200 but with: " + xmlhttp.status)); 549 } 550 }; 551 552 553 /** 554 Returns the possible locations of a module's source file. 555 A module's source file location is determined by treating each module name as a directory. 556 Only the last one is assumed to point to a file. 557 558 **/ 559 publ.getSearchURIsForModuleName=function(name){ 560 var sourceURI; 561 562 var searchURIs = []; 563 564 if(moduleSourceURIs[name] != undefined){ 565 searchURIs.push(moduleSourceURIs[name].format(jsolait)); 566 }else{ 567 name = name.split('.'); 568 if(name.length>1){ 569 if(moduleSourceURIs[name[0]] != undefined){ 570 var uri = moduleSourceURIs[name[0]].format(jsolait); 571 searchURIs.push("%s/%s.js".format(uri, name.slice(1).join('/'))); 572 } 573 searchURIs.push("%s/%s.js".format(packagesURI.format(jsolait),name.join('/'))); 574 } 575 576 for(var i=0;i<moduleSearchURIs.length; i++){ 577 searchURIs.push("%s/%s.js".format(moduleSearchURIs[i].format(jsolait), name.join("/"))); 578 } 579 name = name.join("."); 580 } 581 return searchURIs; 582 }; 583 399 584 /** 400 585 Thrown when a module could not be found. 401 586 **/ 402 jsolait.LoadModuleFailed=Class(jsolait.Exception, function(publ, supr){587 publ.LoadModuleFailed=Class(Exception, function(publ, supr){ 403 588 /** 404 589 Initializes a new LoadModuleFailed Exception. … … 417 602 publ.moduleURIs; 418 603 }); 419 420 604 421 605 /** 422 606 Loads a module given its name(someModule.someSubModule). 423 A module's file location is determined by treating each module name as a directory. 424 Only the last one is assumed to point to a file. 425 If the module's URL is not known (i.e the module name was not found in jsolait.knownModuleURIs) 426 then it will be searched using all URIs found in jsolait.moduleSearchURIs. 607 jsolait.getSearchURIsForModuleName() will be used to determine the possible locations for the source of the module. 608 427 609 @param name The name of the module to load. 428 610 @return The module object. 429 611 **/ 430 jsolait.loadModule = function(name){431 432 if( jsolait.modules[name]){ //module already loaded433 return jsolait.modules[name];612 publ.loadModule = function(name){ 613 614 if(modules[name]){ //module already loaded 615 return modules[name]; 434 616 }else{ 435 617 var src,sourceURI; 436 618 437 var searchURIs = []; 438 439 if(jsolait.moduleSourceURIs[name] != undefined){ 440 searchURIs.push(jsolait.moduleSourceURIs[name].format(jsolait)); 441 }else{ 442 name = name.split('.'); 443 if(name.length>1){ 444 if(jsolait.moduleSourceURIs[name[0]] != undefined){ 445 var uri = jsolait.moduleSourceURIs[name[0]].format(jsolait); 446 searchURIs.push("%s/%s.js".format(uri, name.slice(1).join('/'))); 447 } 448 searchURIs.push("%s/%s.js".format(jsolait.packagesURI.format(jsolait),name.join('/'))); 449 } 450 451 for(var i=0;i<jsolait.moduleSearchURIs.length; i++){ 452 searchURIs.push("%s/%s.js".format(jsolait.moduleSearchURIs[i].format(jsolait), name.join("/"))); 453 } 454 name = name.join("."); 455 } 619 var searchURIs =getSearchURIsForModuleName(name); 456 620 457 621 var failedURIs=[]; … … 459 623 try{ 460 624 sourceURI = searchURIs[i]; 461 src = jsolait.loadURI(sourceURI);625 src = loadURI(sourceURI); 462 626 break; 463 627 }catch(e){ … … 467 631 468 632 if(src == null){ 469 throw new jsolait.LoadModuleFailed(name, failedURIs);633 throw new LoadModuleFailed(name, failedURIs); 470 634 }else{ 471 635 try{//interpret the script 472 var m = jsolait.createModuleFromSource(name, src, sourceURI);636 var m = createModuleFromSource(name, src, sourceURI); 473 637 return m; 474 638 }catch(e){ 475 throw new jsolait.LoadModuleFailed(name, [sourceURI], e);639 throw new LoadModuleFailed(name, [sourceURI], e); 476 640 } 477 641 } … … 479 643 }; 480 644 481 jsolait.__imprt__ = function(name, destinationScope){645 publ.__imprt__ = function(name, destinationScope){ 482 646 var n=name.replace(/\s/g,"").split(":"); 483 647 name = n[0]; … … 488 652 } 489 653 490 var m = jsolait.loadModule(name);654 var m = loadModule(name); 491 655 492 656 if(items.length > 0){ … … 507 671 }; 508 672 509 jsolait.CreateModuleFailed=Class(jsolait.Exception, function(publ, supr){673 publ.CreateModuleFailed=Class(Exception, function(publ, supr){ 510 674 /** 511 675 Initializes a new CreateModuleFailed Exception. … … 521 685 }); 522 686 523 jsolait.createModule=function(name, source, sourceURI, modFn){524 var newMod = new jsolait.ModuleClass(name, source, sourceURI);687 publ.createModule=function(name, source, sourceURI, modFn){ 688 var newMod = new ModuleClass(name, source, sourceURI); 525 689 526 690 var privateScope={imprt: function(imp){ 527 691 var s = arguments.callee.scope; 528 jsolait.__imprt__(imp, s);692 __imprt__(imp, s); 529 693 }}; 530 694 privateScope.imprt.scope=privateScope; 531 privateScope.Exception = Class( jsolait.Exception, new Function());695 privateScope.Exception = Class(Exception, new Function()); 532 696 privateScope.Exception.prototype.module = newMod; 533 697 698 var locals={ 699 str:str, 700 repr:repr, 701 id:id, 702 bind:bind, 703 isinstance:isinstance, 704 issubclass:issubclass, 705 jsolait:jsolait, 706 Class:Class 707 }; 708 534 709 try{//to run the module source 535 modFn.call(newMod, newMod, privateScope, jsolait.builtin);710 modFn.call(newMod, newMod, privateScope, locals); 536 711 }catch(e){ 537 throw new jsolait.CreateModuleFailed(newMod, e);712 throw new CreateModuleFailed(newMod, e); 538 713 } 539 714 … … 541 716 applyNames(privateScope); 542 717 543 jsolait.modules[name] = newMod;718 modules[name] = newMod; 544 719 return newMod; 545 720 }; 546 721 547 jsolait.createModuleFromSource=function(name, source, sourceURI){722 publ.createModuleFromSource=function(name, source, sourceURI){ 548 723 var modFn = new Function("publ,priv,__builtin__", "with(__builtin__){with(publ){with(priv){\n" + source + "\n}}}"); 549 return jsolait.createModule(name, source, sourceURI, modFn);724 return createModule(name, source, sourceURI, modFn); 550 725 }; 551 726 552 jsolait.Module = function(name, modFn){553 return jsolait.createModule(name, '', '', modFn);727 publ.Module = function(name, modFn){ 728 return createModule(name, str(modFn), '', modFn); 554 729 }; 555 730 … … 563 738 }; 564 739 565 //---------------------------------------------------builtins ------------------------------------------------------- 566 /** 567 Returns a string representation of an object. 568 @param obj The object to return a string repr. of. 569 @return A string repr. the object. 570 **/ 571 var str = String; 572 573 /** 574 Return a String containing a printable representation of an object which can be used with eval() to create an equal object. 575 Objects can cosutumize the the value being returned by repr(obj) by providing a obj.__repr__() method which is called by repr(obj). 576 @param obj The object to create a repr. String from. 577 @return A representation of the object. 578 **/ 579 var repr = function(obj){ 580 if(obj == null){ 581 return null; 582 }else if(obj.__repr__){ 583 return obj.__repr__(); 584 }else{ 585 switch(typeof obj){ 586 case "string": 587 obj = obj.replace(/\\/g,"\\\\").replace(/\"/g,"\\\"").replace(/\n/g, "\\n").replace(/\r/g,"\\r"); 588 return '"' + obj + '"'; 589 case "boolean":case"number": 590 return "" + obj; 591 case "object": 592 var out = []; 593 if(obj == null){ 594 return "null"; 595 }else if(obj instanceof Array){ 596 for(var i=0;i<obj.length;i++){ 597 out.push(repr(obj[i])); 598 } 599 return "[" + out.join(",") + "]"; 600 }else if(obj instanceof Object){ 601 for(var key in obj){ 602 out.push(repr(key) + ":" + repr(obj[key])); 603 } 604 return "{" + out.join(",") + "}"; 605 } 606 } 607 } 608 }; 609 610 /** 611 Returns a unique id for an object. 612 The same object will always return the same id. 613 Most objects are id-able. The following steps are taken to find an id. 614 If the obj has an __id__ property that id will be returned. (all jsolait classes have an __id__ property) 615 If the obj has a __id__ method the return value of that method will be returned.(all jsolait objects have a __id__ method which sets an __id__ property) 616 If the obj is a String the string prefixed with $ is returned. 617 If the obj is a Number the number prefixed with a # is returned as a string. 618 All other objects are not safely id-able and an exception is thrown unless forceId is true. In that case the object will get a unique __id__ property applied which is returned. 619 620 @param obj The object to get the id for. 621 @param forceId=false if true it forces id() to set an __id__ property onto a non id-able object, making it id-able. 622 @return A String containing a id value for the obj. 623 **/ 624 var id = function(obj, forceId){ 625 switch(typeof obj.__id__){ 626 627 case "undefined": 628 if(obj instanceof String || typeof obj == 'string'){ 629 return '$' + obj; 630 }else if(obj instanceof Number || typeof obj == 'number'){ 631 return '#' + obj; 632 }else if(forceId){ 633 obj.__id__ = '@' + (Class.__idcount__++); 634 return obj.__id__; 635 }else{ 636 throw new jsolait.Exception('Objec cannot be IDed: %s'.format(obj)); 637 } 638 639 case "function": 640 return obj.__id__(); 641 642 default: //string 643 return obj.__id__; 644 } 645 }; 646 647 /** 648 Returns a bound method. 649 A bound method is a function which is bound to a specific object. 650 Calling the bound method will call the given function with the this-object inside that function's scope being the object specified. 651 652 @param obj The object the function should be bound to. 653 @param fn A function object the obj will be bound to. 654 @return A method which when run executes the function with the this-object being the obj specified. 655 **/ 656 var bind = function(obj, fn){ 657 return function(){ 658 return fn.apply(obj, arguments); 659 }; 660 }; 661 662 /** 663 Returns if an object is an instance of a specified class or of a direct or indirect subclass thereof. 664 665 It also works for traditional javascript inheritance(i.e. SomeClass=function(){}; SomeClass.prototype=new SuperClass(); ...). 666 Internaly it first checks using instanceof if that fails it uses isinstance(obj.constructor, cls). 667 There are some differences between using isinstance and instanceof. 668 i.e. 669 (123 instanceof Number) == false; 670 isinstance(123, Number) == true; 671 ('abc' instanceof String) == false; 672 isinstance('abc', String) == true; 673 674 @param obj The object to test. 675 @param cls The class to test against. 676 @return True if the object is an instance of cls. False otherwise. 677 **/ 678 var isinstance=function(obj, cls){ 679 if(obj instanceof cls){ 680 return true; 681 }else{ 682 return issubclass(obj.constructor, cls); 683 } 684 }; 685 686 /** 687 Returns if a cls is a direct or indirect subclass of another. 688 689 A class is always a subclass of itself and Object is the base for all classes. 690 A class is a subclass of baseclass if it's prototype is an instance of baseclass. 691 A class is a subclass of baseclass if any of it's __bases__ is a subclass of baseclass. 692 If there are no __bases__ defined there is no way to findout about inheritance besides 693 the prototype chain which was checked by instanceof before, so false is returned. 694 695 @param cls The class to test. 696 @param baseclass The assumed superclass. 697 @return True if cls is a subclass of baseclass otherwise false. 698 **/ 699 var issubclass=function(cls, baseclass){ 700 if(baseclass === Object || cls===baseclass || (cls.prototype instanceof baseclass)){ 701 return true; 702 }else{ 703 var bases = cls.__bases__; 704 if(bases != null){ 705 for(var i=0;i<bases.length;i++){ 706 if(bases[i] === baseclass){ 707 return true; 708 } 709 } 710 for(var i=0;i<bases.length;i++){ 711 if(issubclass(bases[i], baseclass)){ 712 return true; 713 } 714 } 715 } 716 return false; 717 } 718 }; 719 720 jsolait.builtin={ 721 str:str, 722 repr:repr, 723 id:id, 724 bind:bind, 725 isinstance:isinstance, 726 issubclass:issubclass, 727 jsolait:jsolait, 728 Class:Class 729 }; 730 740 731 741 //---------------------------------------------------String Format ------------------------------------------------------- 732 742 /** … … 825 835 if(sf){ 826 836 if(sf.join("") != this){ 827 throw new jsolait.Exception("Unsupported formating string.");828 } 829 }else{ 830 throw new jsolait.Exception("Unsupported formating string.");837 throw new Exception("Unsupported formating string."); 838 } 839 }else{ 840 throw new Exception("Unsupported formating string."); 831 841 } 832 842 var rslt=""; … … 843 853 }else if(s=="%s"){ //making %s faster 844 854 if(cnt>=arguments.length){ 845 throw new jsolait.Exception("Not enough arguments for format string.");855 throw new Exception("Not enough arguments for format string."); 846 856 }else{ 847 857 obj=arguments[cnt]; … … 860 870 obj = arguments[0][frmt.key]; 861 871 }else{ 862 throw new jsolait.Exception("Object or associative array expected as formating value.");872 throw new Exception("Object or associative array expected as formating value."); 863 873 } 864 874 }else{//get the current value 865 875 if(cnt>=arguments.length){ 866 throw new jsolait.Exception("Not enough arguments for format string.");876 throw new Exception("Not enough arguments for format string."); 867 877 }else{ 868 878 obj=arguments[cnt]; … … 889 899 s=pad(obj, frmt.paddingFlag, frmt.minLength); 890 900 }else{ 891 throw new jsolait.Exception("Character of length 1 required.");901 throw new Exception("Character of length 1 required."); 892 902 } 893 903 }else{ 894 throw new jsolait.Exception("Character or Byte required.");904 throw new Exception("Character or Byte required."); 895 905 } 896 906 }else if(typeof obj == "number"){ … … 951 961 s=pad(s, frmt.paddingFlag, frmt.minLength);//do padding and justifiing 952 962 }else{ 953 throw new jsolait.Exception("Number required.");963 throw new Exception("Number required."); 954 964 } 955 965 } … … 1008 1018 }; 1009 1019 1010 applyNames(jsolait); 1011 return jsolait; 1012 }()); 1020 applyNames(publ); 1021 1022 return publ; 1023 }}}({})); branches/experimental/jsolait/jsolait.wsf
r71 r72 46 46 var ForReading = 1, ForWriting = 2; 47 47 48 var print = __builtin__.print = function(m){48 print = function(m){ 49 49 var s=[]; 50 50 for(var i=0;i<arguments.length;i++){ … … 55 55 } 56 56 57 var pprint= __builtin__.pprint=function(m, indent){57 pprint= function(m, indent){ 58 58 var m = m.split("\n"); 59 59 branches/experimental/jsolait/lib/asyncimprt.js
r71 r72 1 2 1 3 var applyNames=function(container){ 2 4 for(var n in container){ … … 63 65 }; 64 66 65 publ.getSearchURIsForModuleName=function(name){ 66 var sourceURI; 67 68 var searchURIs = []; 69 70 if(jsolait.moduleSourceURIs[name] != undefined){ 71 searchURIs.push(jsolait.moduleSourceURIs[name].format(jsolait)); 72 }else{ 73 name = name.split('.'); 74 if(name.length>1){ 75 if(jsolait.moduleSourceURIs[name[0]] != undefined){ 76 var uri = jsolait.moduleSourceURIs[name[0]].format(jsolait); 77 searchURIs.push("%s/%s.js".format(uri, name.slice(1).join('/'))); 78 } 79 searchURIs.push("%s/%s.js".format(jsolait.packagesURI.format(jsolait),name.join('/'))); 80 } 81 82 for(var i=0;i<jsolait.moduleSearchURIs.length; i++){ 83 searchURIs.push("%s/%s.js".format(jsolait.moduleSearchURIs[i].format(jsolait), name.join("/"))); 84 } 85 name = name.join("."); 86 } 87 return searchURIs; 88 }; 67 89 68 90 69 publ.loadModule = function(name, returncb){ … … 93 72 returncb(jsolait.modules[name], null); 94 73 }else{ 95 var searchURIs = getSearchURIsForModuleName(name);74 var searchURIs = jsolait.getSearchURIsForModuleName(name); 96 75 var failedURIs=[]; 97 76 loadURI(searchURIs.shift(), function(src, sourceURI, err){
