View Full Version : Dynamically Generate LZX
kjc5664
06-14-2005, 03:33 PM
Is it possible to generate and compile LZX dynamically ???
Yes it can be done, but the compiler is pretty slow at the moment, so you'd have to really really want to do it that way as opposed to some more data driven approach.
The compiler needs to be rewritten for speed, probably a factor of five or ten is possible, but no one has had the time to do that so far. The Javascript compiler is written in a dialect of Python which compiles to Java, and that extra layer of abstraction costs in compilation time.
kjc5664
06-15-2005, 08:29 AM
What I want to do is generate views dynamically based on data that is stored in a DB.
Oh, that's different.
There's a couple of ways to do that.
You can create views at runtime using the "new" operator. So if you have defined a class named "myclass" in lzx
<class name="myclass" ....>
...
</class>
You can say in a method or script block
new myclass(parentview, attributes);
so you could do
new myclass(canvas, {bgcolor: 0xff0000, x: 100});
There are also automatic data mapping facilities to map a dataset into a view or replicated list of views, using the XPATH query syntax.
cjburkha
06-30-2005, 09:47 AM
I would like to do this too.
I see in the examples how they do it, writing a temp file.
I wonder, is there any way to dynamically generate the lzx without using a temp file? Can I send my file like this http://x?<canvas><text>foo</text></canvas>
and expect to get some swf back?
Of course I am missing x above, that is kind of my question!
Well, sort of. The Laszlo debugger works by sending an HTTP request with Javascript expressions up to the server, which compiles them into .swf files which are sent back in the reply.
However, the LPS server doesn't have a path through the compiler which does the XML processing for LZX source code, it just has the "eval" request type for straight script code.
Again, I don't think the compiler is fast enough for you to want to do this on a production site. But if you want to do this as an "application generator" service or something, it would be pretty easy to do. The LZX compiler has an entry point in the org.openlaszlo.compiler.Compiler class. You can see an example in the Main.java class there for the command line compiler.
If you want to do this, go ahead and dive in, I can try to answer questions you may have. Several other people have written their own wrappers around the core compiler, for various projects.
cjburkha
06-30-2005, 10:01 AM
Thanks for your fast reply. I'll try what you suggest, and probably come back with some questions if you are willing.
Thanks again.
cjburkha
07-06-2005, 06:15 AM
I've been looking at this over the last couple days, and could use a couple of pointers.
I tried to look into how the debugger works, and I was able to see what it throws at the server. This seems interesting url=http%3A%2F%2F192%2E168%2E0%2E50%3A8080%2Fgcg%2 F%5F%5Fdebugger
but I can't see how to hit the debugger directly, even with just a eval statment. I can't find much documentation on the debugger besides how to use the application itself. Could you point me to a link?
The LZX compiler has an entry point in the org.openlaszlo.compiler.Compiler class. You can see an example in the Main.java class there for the command line compiler.
This seems more promising. I'm not a Java programmer, but I've extended classes in C++ and .NET, so I might be able to figure it out.
I have two questions about this part
1. org.openlaszlo.compiler.Compiler.class is complied, and I found a decompiler to look at it, but I think the source should be around somewhere. Could you tell me where to look?
Several other people have written their own wrappers around the core compiler, for various projects.
Can you list any specifics? Maybe they have some details about their project on website/blog that will help me get started.
Thanks again for your time.
Hello all
(Henry could you please give an example for your respond above? thanks in advance)
and thanks for this valuable thread,
Well basically I don't know the exact layering of the different generation components but I realized that creation of a large number of low level object instances like <text>/<view> takes a very long time.
I have a customer request for an application which represents a maping graph that can contain over 200 items related to each other with lines (the number of the objects at all is probably higher than if you use <view> for the lines).
It is a sort of topic maps app wich will load the next realted objects dynamically form DB. Well basically they have an Java applet currently which can represent a large number of objects without any signifcant performance leaks.(it should be said that the items are loaded from an XML file here and not from a DB but at least the rendering part is very fast).
I triggerd a small onload script which dynamicaly creates 500 views or text objects without any relations or lines at all and it takes me over 15 sec to retrieve the resut. Additionaly IE starts to strugle around about scripts running over 7 seconds. Well I didn't invest any time on structuring or reusing of already created views but basically tested the performance of the compiler which is kind of slow.
Are there any workarounds like pooling for datasets, hacking the compiler or something else.
Would be great to hear from you'all
Thanks,
rtg
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.