Slick Forums
http://slick.ninjacave.com/forum/

EasyLua - Easy implementation of lua in java | Updated!
http://slick.ninjacave.com/forum/viewtopic.php?f=11&t=2095
Page 1 of 1

Author:  Yohanu [ Fri Nov 06, 2009 10:30 am ]
Post subject:  EasyLua - Easy implementation of lua in java | Updated!

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

Author:  arielsan [ Mon Jan 04, 2010 1:20 pm ]
Post subject: 

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.

Author:  Yohanu [ Mon Jan 11, 2010 8:04 am ]
Post subject: 

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

Author:  Squizzle [ Sun Jan 02, 2011 8:57 pm ]
Post subject: 

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

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/