Script Java in Luban Language

P

peterx

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++
 
A

Alan Krueger

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>
 
N

Noodles Jefferson

Alan Krueger took the hamburger said:
<sarcasm>
Since as we all know, these are features clearly lacking in Java.
</sarcasm>

I thought namespaces was more microsoft specific.

--
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.
 
P

peterx

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.
 
C

Chris Uppal

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
 
P

peterx

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
 
P

peterx

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);
 
A

Alan Krueger

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);

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.
 
C

Chris Uppal

Alan said:
What does Luban add except another syntax to learn?

Um, did you actually /read/ the material on the website that Peter referenced ?

-- chris
 
A

Alan Krueger

Chris said:
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.
 
D

David N. Welton

Alan said:
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.

--
David N. Welton
- http://www.dedasys.com/davidw/

Linux, Open Source Consulting
- http://www.dedasys.com/
 
C

Chris Uppal

Alan said:
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
 
A

Alan Krueger

Chris said:
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.
 
R

Roedy Green

* 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.
 
C

Chris Uppal

Alan Krueger wrote:

[me:]
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:

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
 
A

Alan Krueger

Chris said:
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.
 
C

Chris Smith

Alan Krueger said:
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?

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Alan Krueger

Chris said:
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 );
}
 
C

Chris Smith

Alan Krueger said:
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)

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.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Alan Krueger

Chris said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top