Let's first make an experiment:
1. Build a test class
-
Publicclass Testa {
Public Function A (): String {
Return "aaaa"
}
}
2. parse this code into an ABC file that has packaged the SWF header and then:
(For more information, see as3eval)
00000000 46 57 53 09 6C 01 00 00 78 00 03 E8 00 00 0b B8 | FWS. l ...... x ...... |
00000010 00 00 0C 01 00 44 11 08 00 00 00 3f 12 49 01 00 | ...... D .....?. I .. |
00000020 00 10 00 2E 00 01 01 01 11 00 06 4f 62 6a 65 63 | .......... objec |
00000030 74 05 41 72 72 61 79 06 52 65 67 45 78 70 04 74 | T. array. Regexp. T |
00000040 65 73 74 10 3C 23 69 6e 74 65 72 6e 61 6C 20 74 | est. <# Internal T |
00000050 65 73 74 3E 08 69 6e 74 65 72 6e 61 6C 09 4E 61 | est>. Internal. Na |
00000060 6D 65 73 70 61 63 65 06 70 75 62 6C 69 63 05 54 | mespace. Public. T |
00000070 65 73 74 41 07 70 72 69 61 61 74 65 09 70 72 6f | esta. Private. Pro |
00000080 74 65 63 74 65 64 01 61 61 61 61 61 0a 24 63 | tected. A. AAAA. $ c |
00000090 6f 6e 73 74 72 75 63 74 06 24 63 69 6e 69 74 06 | onstruct. $ cinit. |
201700a0 16 01 17 06 08 01 05 0a 18 0a 02 01 03 0C 07 01 | ...... |
201700b0 02 07 01 03 07 01 07 02 07 07 07 03 08 07 02 09 | ...... |
201700c0 07 03 0a 09 02 01 07 04 0b 07 04 0C 07 03 0d 04 | .......... |
201700d0 00 00 0d 00 00 00 0f 02 00 00 10 00 00 00 00 00 | ...... |
201700e0 00 01 07 08 09 05 00 01 01 0b 01 00 00 02 09 | .......... |
201700f0 06 00 05 04 08 0a 06 00 05 05 08 01 03 04 06 | .......... |
00000100 00 05 02 08 06 06 00 05 03 08 07 04 00 04 00 | ...... |
00000110 01 02 00 01 0C D0 30 F1 05 2C 0e D5 D1 08 01 48 | ...... 0 ......, ...... H |
00000120 47 00 00 01 05 02 00 02 15 F1 05 D0 2a 30 1D 57 | G ...... * 0. w |
00000130 2a D5 2a 1C D0 49 00 1D D0 30 30 08 01 47 00 00 | *. *... I... 00... g... |
00000140 02 01 01 00 01 03 D0 30 47 00 00 03 02 01 00 02 | ...... 0g ...... |
00000150 17 D0 30 F1 05 5d 08 66 08 2a 30 58 00 1D 2a 30 |... 0...]. f. * 0x... * 0 |
00000160 F1 05 1D 64 2B 68 07 47 00 00 40 00 |... d + H. G... @. |
Copy the binary file to t.swf.
3. Create a new Flex Project Test
Then let it unzip t.swf and execute the method in it:
-
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.ModuleEvent; private function init():void { var loader : Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event) : void { var wrapperClass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition('TestA') as Class; var wrapper:Object = new wrapperClass(); trace(wrapper.a()); }); var request : URLRequest = new URLRequest("t.swf"); var context:LoaderContext = new LoaderContext(); context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain); loader.load(request, context); } private function onComplete(e:Event) : void { var loader : Loader = (e.target as Loader); } ]]> </mx:Script></mx:Application>
4. debugging. The output result is AAAA.
========================================================== =====
From 1-> 2, it can be made through as3eval. It does not require flex server, that is, it does not require server support such as Java.
This is entirely because as3 is parsing the code snippet of as3 and then generating the ABC bytecode.
Step 2 can be saved as a file, or you can refer to as3eval, an article other than avm2-Tamarin, without permanently converting it into a file or database content and directly reading it into the memory.
From the above analysis, we can see that step 1 can be put into the database, and the database can be released immediately after Step 3 is parsed. You can also give the user a text box for timely input and online resolution, all of this is not through the server.
========================================================== =====
With online parsing, you can directly serialize the file into a SWF file without compilation, and then read it,
That is to say, we use as3 to compile the code snippet of as3.
At the same time, users can directly input content and perform memory compilation and parsing locally, thus ignoring the server and avoiding pressure.
You can also input a custom as3 DSL and submit it to the database for storage. When you use it, extract the DSL and parse it,
You no longer need to use the server-side Java compilation to avoid security issues.
Using as3eval to make DSL is as flexible as Ruby's DSL, and almost any rules can be customized and then parsed locally.
Let's first make an experiment:
1. Build a test class
-
Publicclass Testa {
Public Function A (): String {
Return "aaaa"
}
}
2. parse this code into an ABC file that has packaged the SWF header and then:
(For more information, see as3eval)
00000000 46 57 53 09 6C 01 00 00 78 00 03 E8 00 00 0b B8 | FWS. l ...... x ...... |
00000010 00 00 0C 01 00 44 11 08 00 00 00 3f 12 49 01 00 | ...... D .....?. I .. |
00000020 00 10 00 2E 00 01 01 01 11 00 06 4f 62 6a 65 63 | .......... objec |
00000030 74 05 41 72 72 61 79 06 52 65 67 45 78 70 04 74 | T. array. Regexp. T |
00000040 65 73 74 10 3C 23 69 6e 74 65 72 6e 61 6C 20 74 | est. <# Internal T |
00000050 65 73 74 3E 08 69 6e 74 65 72 6e 61 6C 09 4E 61 | est>. Internal. Na |
00000060 6D 65 73 70 61 63 65 06 70 75 62 6C 69 63 05 54 | mespace. Public. T |
00000070 65 73 74 41 07 70 72 69 61 61 74 65 09 70 72 6f | esta. Private. Pro |
00000080 74 65 63 74 65 64 01 61 61 61 61 61 0a 24 63 | tected. A. AAAA. $ c |
00000090 6f 6e 73 74 72 75 63 74 06 24 63 69 6e 69 74 06 | onstruct. $ cinit. |
201700a0 16 01 17 06 08 01 05 0a 18 0a 02 01 03 0C 07 01 | ...... |
201700b0 02 07 01 03 07 01 07 02 07 07 07 03 08 07 02 09 | ...... |
201700c0 07 03 0a 09 02 01 07 04 0b 07 04 0C 07 03 0d 04 | .......... |
201700d0 00 00 0d 00 00 00 0f 02 00 00 10 00 00 00 00 00 | ...... |
201700e0 00 01 07 08 09 05 00 01 01 0b 01 00 00 02 09 | .......... |
201700f0 06 00 05 04 08 0a 06 00 05 05 08 01 03 04 06 | .......... |
00000100 00 05 02 08 06 06 00 05 03 08 07 04 00 04 00 | ...... |
00000110 01 02 00 01 0C D0 30 F1 05 2C 0e D5 D1 08 01 48 | ...... 0 ......, ...... H |
00000120 47 00 00 01 05 02 00 02 15 F1 05 D0 2a 30 1D 57 | G ...... * 0. w |
00000130 2a D5 2a 1C D0 49 00 1D D0 30 30 08 01 47 00 00 | *. *... I... 00... g... |
00000140 02 01 01 00 01 03 D0 30 47 00 00 03 02 01 00 02 | ...... 0g ...... |
00000150 17 D0 30 F1 05 5d 08 66 08 2a 30 58 00 1D 2a 30 |... 0...]. f. * 0x... * 0 |
00000160 F1 05 1D 64 2B 68 07 47 00 00 40 00 |... d + H. G... @. |
Copy the binary file to t.swf.
3. Create a new Flex Project Test
Then let it unzip t.swf and execute the method in it:
-
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.ModuleEvent; private function init():void { var loader : Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event) : void { var wrapperClass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition('TestA') as Class; var wrapper:Object = new wrapperClass(); trace(wrapper.a()); }); var request : URLRequest = new URLRequest("t.swf"); var context:LoaderContext = new LoaderContext(); context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain); loader.load(request, context); } private function onComplete(e:Event) : void { var loader : Loader = (e.target as Loader); } ]]> </mx:Script></mx:Application>
4. debugging. The output result is AAAA.
========================================================== =====
From 1-> 2, it can be made through as3eval. It does not require flex server, that is, it does not require server support such as Java.
This is entirely because as3 is parsing the code snippet of as3 and then generating the ABC bytecode.
Step 2 can be saved as a file, or you can refer to as3eval, an article other than avm2-Tamarin, without permanently converting it into a file or database content and directly reading it into the memory.
From the above analysis, we can see that step 1 can be put into the database, and the database can be released immediately after Step 3 is parsed. You can also give the user a text box for timely input and online resolution, all of this is not through the server.
========================================================== =====
With online parsing, you can directly serialize the file into a SWF file without compilation, and then read it,
That is to say, we use as3 to compile the code snippet of as3.
At the same time, users can directly input content and perform memory compilation and parsing locally, thus ignoring the server and avoiding pressure.
You can also input a custom as3 DSL and submit it to the database for storage. When you use it, extract the DSL and parse it,
You no longer need to use the server-side Java compilation to avoid security issues.
Using as3eval to make DSL is as flexible as Ruby's DSL, and almost any rules can be customized and then parsed locally.