Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (512)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  A Java scripting language -- Leola  (Read 4802 times)
0 Members and 1 Guest are viewing this topic.
Offline newera31
« Posted 2013-04-16 22:47:49 »

Hello Java-Gaming.org,

I have been working on a programming language on and off now for about 3 years.  It doesn't really have an objective other than for entertainment for myself.  With that said, I have found it quite fun to program in!

It is written in Java and interfaces fairly well with Java.  If you are interested you can check out the project page at https://github.com/tonysparks/leola.

As a proof of concept I began to write a simple 2D game framework (currently just wraps Java2D) for simple/rapid prototyping.

Here is a screenshot of a simple Space Invaders clone:


Here is the Leola source code for the Space Invaders clone: http://pastebin.java-gaming.org/4584c18435b


Here is another screenshot of an in progress top down shooter:



Thank you all for your time!

-Tony
Offline ReBirth
« Reply #1 - Posted 2013-04-17 02:24:13 »

Looks like Javascript, a lot. Do you have benchmark on how well it performs calculus?

Offline newera31
« Reply #2 - Posted 2013-04-17 13:59:11 »

It does borrow a lot of features from JavaScript.  The key differences are explicit language support for classes and namespaces.  I almost think it being so closely related to JavaScript is a good thing, in that it is easy to read and write.

I don't have a benchmark for the calculus, but I'd imagine they wouldn't be very good compared to C or Java.  Calculus isn't necessarily Leola's forte, the example was to show off closures and higher order functions.

For an interpreted language, it is actually fairly "fast".  The simple prototype games average ~60 FPS, which is pretty good given that 90% of the code is in Leola (the render calls and game loop are in Java).

I also use Leola for simple scripting tasks (updating/querying databases, moving/parsing files, etc.) and have never encountered performance problems.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-04-17 15:37:53 »

Very cool.

How did you learn how to write your own scripting language, with classes, closures, and all that? Shocked

Offline newera31
« Reply #4 - Posted 2013-04-17 16:56:36 »

Thanks davedes!

It's just like anything else, just by taking the time to dig into it.  I initially toyed around with parser generators (in particular Antlr) but found them extremely confusing and cumbersome to use.  Once I decided to write the lexing/parsing manually, things started going smoothly.  The book that helped out tremendously is http://www.amazon.com/Writing-Compilers-Interpreters-Software-Engineering/dp/0470177071.

My initial implementation was just a very simple Abstract Syntax Tree walker, essentially what BeanShell is.  Performance was not very good at all, but it motivated me in the sense that creating a language was "doable".
Offline matheus23

JGO Kernel


Medals: 109
Projects: 3


You think about my Avatar right now!


« Reply #5 - Posted 2013-04-20 10:25:55 »

Wow! Shocked
Really amazing!

I've seen those switch'es in the example code...
Can we do pattern matching with it?

Would be AWESOME!

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline newera31
« Reply #6 - Posted 2013-04-20 22:29:00 »

Thanks   Cheesy

There is a 'switch' and a 'case' statement, they only differ in that the 'switch' executes a statement when a condition is met, and the 'case' executes an expression.  They both support a type of pattern matching, not as robust as say Scala's pattern matching -- but still useful.

Here are some examples:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
// finds the first match
var myFavoriteTeam = "Packers"
var status = case myFavoriteTeam {
   when "Bears" -> "the worst"
   when "49ers" -> "OK"
   when "Seahawks" -> "Meh"
        when 1234 -> "Just showing the conditions can be anything"
   when "Packers" -> "The greatest"

   else "not so good"
}

println(status) // prints "The greatest"


class X();
class Y();

var x = new X()

// finds the first match
switch {
   when x is Y -> println("x is Y")
   when x is X -> println("x is X")  
   else println("Unknown")
} // prints "x is X"

class Z() is Y(); // Z inherits from Y
var z = new Z()


// finds the first match, in this case it is Y because Z inherits from Y
switch {
   when z is X -> println("z is X")
   when z is Y -> println("z is Y")
   
   else println("Unknown")
} // prints "z is Y"
Offline Sammidysam
« Reply #7 - Posted 2013-04-20 22:37:41 »

This looks really cool!  I would love to test it out--is there a compiled library JAR out there?  Also, I love the love for the Packers and hatred of the Bears Cheesy
Offline concerto49

Junior Duke





« Reply #8 - Posted 2013-04-21 00:05:40 »

Great fun building a language. Thought about it too, however IDE support or lack of is problematic.

High performance, fast network, affordable price VPS - Cloud Shards
Available in Texas, New York & Los Angeles
Need a VPS Upgrade?
Offline ReBirth
« Reply #9 - Posted 2013-04-21 02:36:00 »

An editor like Sublime or Notepad++ is enough for this.

Why call this scripting? AFAIK scripting is something like HTML, CSS, JSON, etc where there is no logic inside.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SHC
« Reply #10 - Posted 2013-04-21 03:04:37 »

Why call this scripting? AFAIK scripting is something like HTML, CSS, JSON, etc where there is no logic inside.

Then why they call
JavaScript
,
ActionScript
,
VBScript
with their names? Don't they have logic in them?

Offline ReBirth
« Reply #11 - Posted 2013-04-21 03:07:08 »

They do. But I talked about the "scripting" verb, which is used by web designer on their HTML & CSS replacing "coding"/"programming" on other side.

Offline newera31
« Reply #12 - Posted 2013-04-21 03:15:56 »

Yeah, the Bears suck  Wink


I use Notepad++ (with my own custom syntax highlighting) with the NppExec plugin -- works awesome.  I bound CTRL+SHIFT+C to compile and run the current file.  As ReBirth has mentioned, an IDE would be overkill.


You can download the jar file, a windows executable file (for convenience) and the space invaders game here: https://dl.dropboxusercontent.com/u/11954191/leola.zip

To install, just extract to a directory (ex. C:\leola)

To run the space invaders game, open a cmd prompt and navigate to the install directory and
run the following command:

1  
C:\leola>leola.exe "./live.leola" "./spaceinvaders/spaceInvaders.leola"



A cool feature about the game framework is that it detects when a file has changed.  If a file has changed, it will reload the game.  This helps facilitate the rapid prototyping by giving almost instant feedback when modifying the code.

If anyone is interested, I can put up a short tutorial on how to setup Notepad++ for nice easy integration with Leola.

Thanks!

Tony
Offline newera31
« Reply #13 - Posted 2013-04-21 03:22:26 »

@ReBirth -- with regards to calling it "scripting"; I think of a small little one-off program as just little scripts to quickly accomplish a task.  I got this nomenclature from shell scripts.  Same concept, at least for me.  I see what you are saying though.
Offline SHC
« Reply #14 - Posted 2013-04-21 03:26:11 »

I was really interested in this. (Also got a copy of the book you mentioned from a local shop). However got one doubt though.

1  
class Entity(pos, speed) {


What if I want to do multiple constructors? Is this available?

Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #15 - Posted 2013-04-21 03:30:10 »

Scripting: Using pre-defined commands to automate a process which could be done by a human.

Offline newera31
« Reply #16 - Posted 2013-04-21 03:40:21 »

There aren't any operator overloads in Leola (a slight lie).  A work around can be to use a Map to populate the constructor such as:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
// the map can contain values that you want to
// populate in the class.  If the value is not supplied, use a default
class Entity(settings) {
   var pos = settings.pos
   var vel = settings.vel

   var someOptionalParameter = case when settings.option != null -> settings.option else "defaultValue"
}


var hero = new Entity({
   pos -> live:math:newVec2(),
   vel -> live:math:newVec2(),
})

var enemy = new Entity({
   pos -> live:math:newVec2(),
   vel -> live:math:newVec2(),
   someOptionalParameter -> "Something that isn't the defaultValue"
})

/* You can even add properties dynamically after construction */
enemy.somethingNew = "a new property"
enemy.somethingElse = def() return "a new function"

println( enemy.somethingNew ) // prints "a new property"
println( enemy.somethingElse() ) // prints "a new function"
Offline Agro
« Reply #17 - Posted 2013-04-21 03:43:49 »

Does Leola layer on top of Java? So you can quickly write an implementation for networking, or do you have to manually write new things etc?

Offline newera31
« Reply #18 - Posted 2013-04-21 04:03:08 »

@Argo -- I'm not exactly sure what you are asking.  Are you asking if you can interop directly with Java classes without writing a "binding" layer?

The answer is yes, the "binding" layer is completely optional.  I only recommend using it when you want to have a closer integration with Leola.  For instance in the SQL library I have this construct:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
// conn is a simple "wrapper" around java.sql.Connection.  It adds some useful
// methods for taking advantage of Leola's features
var conn = db:connect("dbUrl", "myuser", "password")

/* wraps all of the delete statements into 1 transaction */
conn.transaction(def() {
 
  conn.query("delete from table where table.id = :ID").params({ID -> 1234}).update()
  conn.query("delete from table2 where table2.id = :ID").params({ID -> 9876}).update()
})


If you want to instantiate a Java object, it is as simple as:

1  
2  
3  
var javaArray = new java.util.ArrayList()
javaArray.add( 20 )
println(javaArray.get(0) ) // prints "20"
Offline Agro
« Reply #19 - Posted 2013-04-21 04:32:53 »

Oh, that's neat. I love that. I'll try it out later!

Offline matheus23

JGO Kernel


Medals: 109
Projects: 3


You think about my Avatar right now!


« Reply #20 - Posted 2013-04-21 08:18:40 »

Awesome. Definitely awesome.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Sammidysam
« Reply #21 - Posted 2013-04-21 14:23:12 »

For me, the graphics on the space invaders clone is flashing crazily and I heard no sound.  Obviously there seem to be some bugs.  Do you have any idea what's going on?
Offline newera31
« Reply #22 - Posted 2013-04-21 14:39:27 »

The sound is currently disabled -- there is a memory leak that I haven't fixed yet.

As for the flashing, I have not encountered that.  Does it just seem like it is rendering very slow?
Offline Phased
« Reply #23 - Posted 2013-04-21 14:42:59 »

You should enter Ludum Dare 26 with Leola, mention you created the language, give a link to the download in a "im in" post, and make a good game to show it off for the event, you may get a bit bigger community supporting it.
Offline newera31
« Reply #24 - Posted 2013-04-21 14:51:55 »

That does sound like a great idea.  Alas, with two kids I doubt I would ever get the time.  As it is, I'm lucky to get ~5 hours a week to code on my personal projects.

Ludum dare sounds like so much fun though.
Offline Phased
« Reply #25 - Posted 2013-04-21 15:01:04 »

Try and scavenge those extra minutes over the 48 hours or even the 72 hour jam, even if the game is not great or hardly fits the theme, put it up, just mention you did not have the time, and you were able to produce this in x amount of time.

If not post up on the website anyway, mention the language, someone may like it and start following its progress, maybe even enter the next LD with it.
Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #26 - Posted 2013-04-21 19:19:14 »

The best time to post is a few hours before the compo starts (everyone is browsing the site, no-one's really posting) or when things calm down again after the compo.

Offline isteinvids

Junior Duke


Medals: 1



« Reply #27 - Posted 2013-04-30 10:11:19 »

1  
2  
3  
C:\Users\EmirRhouni\Documents\Leola\Leola>java -jar leola.jar "spaceinvaders/spaceInvaders.leola"
Exception in thread "main" java.lang.NullPointerException
        at leola.vm.Leola.main(Leola.java:130)


Tried running Space Invaders, got this error
Anyway, looks neat!
Offline newera31
« Reply #28 - Posted 2013-05-01 22:04:45 »

Try this out:

1  
java -jar leola.jar "./live.leola" "./spaceinvaders/spaceInvaders.leola"


The NPE is from not finding the necessary libraries from not loading the "live.leola" file.
Offline Longor1996
« Reply #29 - Posted 2013-05-09 13:27:30 »

Hey, newera32,

before the view-counter/guest-counter in this thread shoot's up rapidly out of no-reason,
I think I should tell you that I posted a link to this thread in the english minecraft forum in a very well visited thread.

Little question here:
Is it possible to save the bytecode that the leola-vm uses to the harddrive?
And is it also possible to execute bytecode from the harddrive?

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (12 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (45 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!