Slick Forums

Discuss the Slick 2D Library
It is currently Sun Sep 15, 2019 6:19 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Nov 06, 2009 10:30 am 
Offline

Joined: Fri Oct 30, 2009 4:06 pm
Posts: 27
Well, there was no proper library available for this purpose at all in java, so i pretty much wrote an implementation for OOP. All that was available was C-bindings, and that's it, this meant you had to work with the actual stack in order to retrieve data from a LUA-file.

So here's a neat little library that will allow you to parse lua-tables with ease. I love lua as a data-storage system as it's very light-weight, incredibly fast, and has a nice syntax.

Javadocs are included and the native library file for windows that is required. In case you need one for another operating system, get it here: http://luabinaries.luaforge.net/download.html

There's an example on how to load a table and iterate it's values in com.easylua.examples.TableTest

In case you want an example right here:
Code:
package com.easylua.examples;

import com.easylua.*;

/**
 * An example class on loading a table and outputting it's data.
 */
public class TableTest {

    public static void main(String[] args) {
        new TableTest();
    }

    public TableTest() {
        LuaScript script = LuaScript.parse("./res/tabletest.lua");
        LuaTable table = script.getTable("testTable");
        printTable(table);
        System.out.println("Test executed successfully!");

    }

    public void printTable(LuaTable table) {
        for(LuaValue val : table.getValues()) {
            if(val instanceof LuaBoolean) {
                LuaBoolean bool = (LuaBoolean) val;
                System.out.println(bool.getName() + " = " + bool.getValue());
            } else if(val instanceof LuaNumber) {
                LuaNumber num = (LuaNumber) val;
                System.out.println(num.getName() + " = " + num.getValue());
            } else if(val instanceof LuaString) {
                LuaString string = (LuaString) val;
                System.out.println(string.getName() + " = " + string.getValue());
            } else if(val instanceof LuaTable) {
                LuaTable tab = (LuaTable) val;
                printTable(tab);
            }
        }
    }
}


That's about it, i will be improving this overtime as i myself need more features from LUA in my projects.

Download Link: http://usenet.eatddos.info/easylua/down ... ua-0.2.zip

I noticed my old link was broken so here is a working one. It is updated to revision 0.2 as well and contains some new functionality such as ability to call lua functions and get global variables.

Note: I didn't really know where to post this, so i hope this section is alright. It's not really open source at the moment, however that will happen soon enough

Enjoy :)


Last edited by Yohanu on Sun Jan 17, 2010 4:24 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 04, 2010 1:20 pm 
Offline
Regular
User avatar

Joined: Tue Apr 07, 2009 12:58 pm
Posts: 232
Location: Uruguay
If you want dynamic behavior, you should try some dynamic languages like Scala or Groovy (both compile over JVM).

They would be more easy to write, you don't need almost anything to use them inside your Java code.

I only tried Groovy, but I heard Scala is really great also.

Take a look at http://groovy.codehaus.org/

Obviously, if you are trying to reuse a lot of Lua code you already have, this is not an option.

By the way: http://www.lua.org/about.html (read the part of LUA and Lua) :D

See ya.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 11, 2010 8:04 am 
Offline

Joined: Fri Oct 30, 2009 4:06 pm
Posts: 27
arielsan wrote:
If you want dynamic behavior, you should try some dynamic languages like Scala or Groovy (both compile over JVM).

They would be more easy to write, you don't need almost anything to use them inside your Java code.

I only tried Groovy, but I heard Scala is really great also.

Take a look at http://groovy.codehaus.org/

Obviously, if you are trying to reuse a lot of Lua code you already have, this is not an option.

By the way: http://www.lua.org/about.html (read the part of LUA and Lua) :D

See ya.
I am aware of the other languages out there, however a lot of people would rather use Lua for various reasons, since there wasn't any useful library for it in Java i wrote one up :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 02, 2011 8:57 pm 
Offline

Joined: Sun Jan 02, 2011 8:39 pm
Posts: 66
Link is DEAD.

For an alternative try LuaJ.

Get the source code and look in the "test" folder for some nice examples or see the README

Here is a example LoadFile function that returns a LuaFunction that you can invoke later:
Code:
public LuaFunction LoadFile(String fileName) throws IOException{
   File file = new File(fileName);
   if (file.exists()){
       LuaTable _G = org.luaj.vm2.lib.jse.JsePlatform.standardGlobals();
       FileInputStream is = new FileInputStream(file);
       LuaFunction script = null;
       script = org.luaj.vm2.compiler.LuaC.instance.load(is, file.getName(), _G);
       return script;
   }
   return null;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group