@@ -18,18 +18,48 @@ function CpcVmRsx(oVm) {
1818CpcVmRsx . prototype = {
1919 rsxInit : function ( oVm ) {
2020 this . oVm = oVm ;
21+ this . rsxTemporary = { } ; // temporary/dynamic RSX registered at runtime
2122 } ,
2223
2324 rsxIsAvailable : function ( sName ) {
24- return sName in this ;
25+ return ( sName in this . rsxTemporary ) || ( sName in this ) ; // check temporary first, then permanent
26+ } ,
27+
28+ rsxRegister : function ( oRsxConstructor ) {
29+ // Register temporary RSX from constructor
30+ // Constructor should be a function that returns an object with getRsxCommands() method
31+ var oRsxModule , oRsxCommands , sCommand ;
32+
33+ oRsxModule = new oRsxConstructor ( ) ;
34+ if ( oRsxModule . getRsxCommands ) {
35+ oRsxCommands = oRsxModule . getRsxCommands ( ) ;
36+ for ( sCommand in oRsxCommands ) {
37+ if ( oRsxCommands . hasOwnProperty ( sCommand ) ) {
38+ this . rsxTemporary [ sCommand ] = oRsxCommands [ sCommand ] ;
39+ }
40+ }
41+ }
42+ } ,
43+
44+ rsxReset : function ( ) {
45+ // Clear temporary RSX (called when loading new example)
46+ this . rsxTemporary = { } ;
2547 } ,
2648
2749 rsxExec : function ( sName ) { // varargs
28- var aArgs ;
50+ var aArgs , fnRsx ;
2951
30- if ( this . rsxIsAvailable ( sName ) ) {
52+ // Check temporary RSX first, then permanent
53+ if ( sName in this . rsxTemporary ) {
54+ // Temporary RSX: call with this = CpcVm (the VM instance)
55+ fnRsx = this . rsxTemporary [ sName ] ;
56+ aArgs = Array . prototype . slice . call ( arguments , 1 ) ;
57+ fnRsx . apply ( this . oVm , aArgs ) ;
58+ } else if ( typeof this [ sName ] === "function" ) {
59+ // Permanent RSX: call with this = CpcVmRsx
60+ fnRsx = this [ sName ] ;
3161 aArgs = Array . prototype . slice . call ( arguments , 1 ) ;
32- this [ sName ] . apply ( this , aArgs ) ;
62+ fnRsx . apply ( this , aArgs ) ;
3363 } else {
3464 throw this . oVm . vmComposeError ( Error ( ) , 28 , "|" + sName ) ; // Unknown command
3565 }
0 commit comments