Java Forum / General / January 2006
Script Java in Luban Language
peterx@lubankit.org - 21 Dec 2005 16:39 GMT http://www.lubankit.org
Luban Programming Language Beta 2 is released with one major feature addition: the Luban Java Bridge has been built to enable Luban to access arbitrary Java classes, functions and fields. Below listed are the features of the new Luban Java Bridge.
1. Construct Java object of any Java class type. 2. Call any Java object instance member function in a Luban native way 3. Call any Java static class function 4. Read/write any Java object field 5. Read/write any Java static class field. 6. Dynamic checking of Java object type with "instanceof" member function 7. Automatic conversion between Java object and Luban native data object 8. Simple methodology to script and compose Java GUI with Luban code 9. New luban.InvocationQueue Java class to universally pass Java GUI event to Luban by simulating arbitrary Java Interface 10. Sample Luban code to access MySQL through JDBC, compose Java GUI, use Java regular expression and more!
About: Luban is a component oriented scripting language. It was created to be easier than Java and to feature namespaces and interfaces. It has a simple and clean syntax and a property-based component model similar to Java beans. A component can be a process or a composition. All data types and components are saved in a namespace hierarchy. Thread dispatching and synchronization are built in. It also features component interface inheritance, dynamic type checking, reflection, serialization, remote component calls, exception free error handling, and an API to import data new types from C++
Alan Krueger - 21 Dec 2005 18:24 GMT > Luban is a component oriented scripting language. It was created to be > easier than Java and to feature namespaces and interfaces. <sarcasm> Since as we all know, these are features clearly lacking in Java. </sarcasm>
Noodles Jefferson - 21 Dec 2005 19:23 GMT > > Luban is a component oriented scripting language. It was created to be > > easier than Java and to feature namespaces and interfaces. > > <sarcasm> > Since as we all know, these are features clearly lacking in Java. > </sarcasm> I thought namespaces was more microsoft specific.
 Signature Noodles Jefferson mhm31x9 Smeeter#29 WSD#30 sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
NP: "The Road to Chicago" -- Thomas Newman (Road to Perdition Soundtrack)
"Our earth is degenerate in these latter days, bribery and corruption are common, children no longer obey their parents and the end of the world is evidently approaching." --Assyrian clay tablet 2800 B.C.
peterx@lubankit.org - 21 Dec 2005 19:41 GMT I think namespace is practically equivalent to Java package.
And Luban is not trying to have more features than Java. Actually it tries to have a simpler component model to fit for scriptting purpose. It doesn't even do classes, it makes the property based component like Java Bean.
Chris Uppal - 22 Dec 2005 17:25 GMT > And Luban is not trying to have more features than Java. Actually it > tries to have a simpler component model to fit for scriptting purpose. > It doesn't even do classes, it makes the property based component like > Java Bean. FWIW, I found reading the Luban website very interesting. Luban is anything but your typical clone-your-own-scripting-language; it incorporates some distinctly unconventional approaches. At least /I/ have not seen an equivalent to the "structure" concept in any other language. (Unless, perhaps, it is like the "patterns" in Beta -- but then I've never been able to get my head around Beta's patterns...)
-- chris
peterx@lubankit.org - 23 Dec 2005 15:05 GMT Luban's "structure" has some similarities with Java Bean.
When you use the composition feature to build structure, it is analogous to spreadsheet construction.
I got to take a look at Beta's pattern.
-peterx
peterx@lubankit.org - 23 Dec 2005 17:02 GMT Actually it would help if I give some examples to script Java in Luban language
Below two Luban code lines print out current time
now = java::javaobj("java.util.Date"); std::println(obj=now);
Below Luban code opens a Java Swing window and shows message "hello world"
f=java::javaobj("javax.swing.JFrame"); p=java::javaobj("javax.swing.JPanel"); label = java::javaobj("javax.swing.JLabel","hello world"); p.add(label); f.setContentPane(p); f.setVisible(true);
Alan Krueger - 09 Jan 2006 03:07 GMT > Actually it would help if I give some examples to script Java in Luban > language [quoted text clipped - 3 lines] > now = java::javaobj("java.util.Date"); > std::println(obj=now); And the equivalent in Java:
java.util.Date now = new java.util.Date(); System.out.println( now );
What does Luban add except another syntax to learn? It appears to share C++'s fondness for :: as a scoping operator, which to me seems less readable than a simple dot.
Chris Uppal - 09 Jan 2006 09:52 GMT > What does Luban add except another syntax to learn? Um, did you actually /read/ the material on the website that Peter referenced ?
-- chris
Alan Krueger - 10 Jan 2006 03:51 GMT >>What does Luban add except another syntax to learn? > > Um, did you actually /read/ the material on the website that Peter referenced ? Yes, I did. What I see is a syntactic sugar coating on Java. Perhaps you could be more specific about the benefits you see.
David N. Welton - 10 Jan 2006 07:24 GMT >>> What does Luban add except another syntax to learn? >> [quoted text clipped - 3 lines] > Yes, I did. What I see is a syntactic sugar coating on Java. Perhaps > you could be more specific about the benefits you see. I think (and in practice, have implemented it that way in Hecl), that if you're going to combine a scripting language with a lower-level language like Java, you might as well aim for a pretty high level scripting language that does things differently from the low level language.
 Signature David N. Welton - http://www.dedasys.com/davidw/
Linux, Open Source Consulting - http://www.dedasys.com/
Chris Uppal - 10 Jan 2006 10:44 GMT > Yes, I did. What I see is a syntactic sugar coating on Java. Perhaps > you could be more specific about the benefits you see. Eh ? I donb't understand how could you possibly get that impression. Luban isn't even /realated/ to Java. It's a completely different language, with a completely different semantics, indeed a completely different /kind/ of semantics.
What it does have (as one of the language's standard libraries) is a way of bridging over to invoke code written in Java . That bridge works via JNI since the Luban implementation (in C++) is otherwise independent of the JVM.
-- chris
Alan Krueger - 10 Jan 2006 15:43 GMT > Eh ? I donb't understand how could you possibly get that impression. Luban > isn't even /realated/ to Java. It's a completely different language, with a > completely different semantics, indeed a completely different /kind/ of > semantics. Each of the examples given in the Luban documentation seemed to have an obvious complement in Java, though clearly Luban has a different syntax and handles some things implicitly:
* Java can wait for threads to complete, but you need to explicitly add thread synchronization yourself.
* Java can do named (versus positional) parameters, but via a Map rather than built into the language.
* Java can pass everything by value if you always clone everything when passing it somewhere.
Randomly selecting an example, from 3.1 of the Luban documentation:
namespace demo;
struct helloworld() as process { std::println(obj="Hello, world!"); }
The "struct helloworld() as process" looks very much like a class of name helloworld extending Runnable with a call to System.out.println in the run method.
The other examples look equally straightforward to map, with the possible difference of being more verbose in Java.
Roedy Green - 10 Jan 2006 18:22 GMT On Tue, 10 Jan 2006 09:43:25 -0600, Alan Krueger <wgzkid502@sneakemail.com> wrote, quoted or indirectly quoted someone who said :
>* Java can pass everything by value if you always clone everything when >passing it somewhere. Java always passes by value. I think you mean clone objects to avoid callees from being able to change fields in the callers objects who are passed references by value.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Chris Uppal - 11 Jan 2006 11:53 GMT [me:]
> > Eh ? I donb't understand how could you possibly get that impression. > > Luban isn't even /realated/ to Java. It's a completely different [quoted text clipped - 4 lines] > obvious complement in Java, though clearly Luban has a different syntax > and handles some things implicitly: I'm sorry but I cannot at all understand how you can claim that. All I can do is repeat my earlier comment (quoted above), I don't think I have anything more to add to this conversation.
-- chris
Alan Krueger - 11 Jan 2006 13:53 GMT > I'm sorry but I cannot at all understand how you can claim that. All I can do > is repeat my earlier comment (quoted above), I don't think I have anything more > to add to this conversation. Can you provide a specific example of what you mean, rather than sweeping, generic statements? I did.
Chris Smith - 11 Jan 2006 16:02 GMT > > I'm sorry but I cannot at all understand how you can claim that. All I can do > > is repeat my earlier comment (quoted above), I don't think I have anything more > > to add to this conversation. > > Can you provide a specific example of what you mean, rather than > sweeping, generic statements? I did. Read the documentation section from the web site on threads and synchronization. Care to demonstrate the simple, straight-forward mapping from that to Java?
 Signature www.designacourse.com The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
Alan Krueger - 12 Jan 2006 14:05 GMT > Read the documentation section from the web site on threads and > synchronization. Care to demonstrate the simple, straight-forward > mapping from that to Java? Combining the Luban "multiplexer" and "AsyncPrinter" snippets and adding some details to actually test it: (sorry about the formatting, Usenet's not great for that)
import java.util.concurrent.*;
public class MultiplexerDemo { static class Multiplexer implements Runnable { public void run() { System.out.println( "[Multiplexer starting]" ); executor.execute( new Runnable() { public void run() { merge( 1, flow1 ); } } ); executor.execute( new Runnable() { public void run() { merge( 2, flow2 ); } } ); System.out.println( "[Multiplexer ending]" ); starting = false; } public void merge( int flow, BlockingQueue input ) { System.out.println( "[Multiplexer merge flow" + flow + " starting]" ); while ( !executor.isShutdown() ) { Object o = input.poll(); if ( o != null ) merged.add( o ); Thread.yield(); } System.out.println( "[Multiplexer merge flow" + flow + " ending]" ); } public void waitFinish() { while ( starting || !flow1.isEmpty() || !flow2.isEmpty() ) Thread.yield(); } protected boolean starting = true; public BlockingQueue flow1 = new LinkedBlockingQueue(); public BlockingQueue flow2 = new LinkedBlockingQueue(); public BlockingQueue merged = new LinkedBlockingQueue(); } static class AsyncPrinter implements Runnable { public AsyncPrinter( BlockingQueue input ) { this.input = input; } public void run() { System.out.println( "[AsyncPrinter starting]" ); while ( !executor.isShutdown() ) { Object obj = input.poll(); if ( obj != null ) System.out.println( obj ); Thread.yield(); } System.out.println( "[AsyncPrinter ending]" ); } public void waitFinish() { while ( !input.isEmpty() ) Thread.yield(); } public BlockingQueue input = new LinkedBlockingQueue(); } public static void main( String[] args ) { System.out.println( "[main starting]" ); Multiplexer multiplexer = new Multiplexer(); executor.execute( multiplexer ); AsyncPrinter printer = new AsyncPrinter( multiplexer.merged ); executor.execute( printer ); multiplexer.flow1.add( "Line 1 - Flow 1" ); multiplexer.flow2.add( "Line 2 - Flow 2" ); multiplexer.flow2.add( "Line 3 - Flow 2" ); multiplexer.flow1.add( "Line 4 - Flow 1" ); multiplexer.waitFinish(); printer.waitFinish(); executor.shutdown(); try { executor.awaitTermination( 10, TimeUnit.SECONDS ); } catch ( InterruptedException e ) {} System.out.println( "[main ending]" ); } static ExecutorService executor = Executors.newFixedThreadPool( 15 ); }
Chris Smith - 12 Jan 2006 20:31 GMT > > Read the documentation section from the web site on threads and > > synchronization. Care to demonstrate the simple, straight-forward [quoted text clipped - 3 lines] > some details to actually test it: (sorry about the formatting, Usenet's > not great for that) Okay... so obviously this isn't just a simple transliteration of anything from the Luban web site into Java. It's a re-implementation of some of the same tasks. Luban is clearly its own language, and not a "syntactic sugar coating on Java". It's a language of its own, unrelated to Java. Which is what Chris said.
 Signature www.designacourse.com The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
Alan Krueger - 13 Jan 2006 04:08 GMT > Okay... so obviously this isn't just a simple transliteration of > anything from the Luban web site into Java. It's a re-implementation of > some of the same tasks. On the contrary, I constructed that example by taking each piece of the example and using a similar construct in Java. The input and output parts of a Luban struct I mapped to public BlockingQueue instances, the Luban process I mapped to a Runnable instance, and so on. Looking at the examples, I can see the outlines for a Luban-to-Java translation tool.
> Luban is clearly its own language, and not a > "syntactic sugar coating on Java". It's a language of its own, > unrelated to Java. Which is what Chris said. Perhaps you misunderstood what I meant. Consider the above to say "on Java's capabilities". I didn't mean to imply that it precompiled down to Java, or something. I said, "What does Luban add except another syntax to learn?" I idly questioned the benefit of adding yet another language to the mix.
Personally, to someone who has more experience reading and writing Java, the more verbose syntax of an equivalent Java program is clearer and more explicit.
I'm not entirely sure what point you're trying to argue, though, aside from trying to prove someone wrong.
Chris Smith - 13 Jan 2006 05:51 GMT > Perhaps you misunderstood what I meant. Consider the above to say "on > Java's capabilities". I didn't mean to imply that it precompiled down > to Java, or something. Perhaps I did misunderstand. I had understood you to say that Luban was a syntax face-lift for Java, i.e., someone took Java and changed the syntax. Clearly, Luban is its own language completely independent of Java -- despite the fact that Luban has recently introduced the ability to integrate with Java, after the original language existed.
> I'm not entirely sure what point you're trying to argue, though, aside > from trying to prove someone wrong. I was trying to point out that it's not actually true that Luban is Java with a modified syntax.
 Signature www.designacourse.com The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|