lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi all,

This is a small Lua for Windows plugin that adds LuaJava plus some
interesting utilities. Just unzip into the LfW main directory, so that
things like luaj.exe sit next to lua.exe, etc. (If you don't use LfW,
then it should be straightforward anyway; the source is included)

As a general rule, a scripting language should be at least as easy to
use as the main 'system' language. The luajava API can be a bit
clumsy, because _every_ type must be explicitly imported:

    > String = luajava.bindClass("java.lang.String")
    > s =,"hello")
    > print(s)
    userdata: 02DDCEE8
    > print(s:toString())

The `import` function works like the Java statement of the same name,
so that import 'java.lang.*' means that things like String, Integer,
etc will be brought into the global namespace.  As an extra
convenience, when classes are imported, a `__call` metamethod is
defined, so that you can simply create objects by calling the types,
e.g. `String("hello")`.

    > require 'java.import'
    > import 'java.lang.*'
    > s = String("hello")
    > print(s)

As a further convenience, `__tostring` is defined to return the value
of `toString`.

In the examples there is console.lua, which is yet another GUI
interactive Lua prompt, this time using Swing. It doesn't yet have all
the features of lconsole, but I'm getting there.

steve d.