org.keplerproject.luajava
Class LuaState

java.lang.Object
  extended byorg.keplerproject.luajava.LuaState

public class LuaState
extends java.lang.Object

LuaState if the main class of LuaJava for the Java developer. LuaState is a mapping of most of Lua's C API functions. LuaState also provides many other functions that will be used to manipulate objects between Lua and Java.


Field Summary
static java.lang.Integer LUA_ERRERR
          error while running the error handler function.
static java.lang.Integer LUA_ERRFILE
           
static java.lang.Integer LUA_ERRMEM
          memory allocation error.
static java.lang.Integer LUA_ERRRUN
          a runtime error.
static java.lang.Integer LUA_ERRSYNTAX
          syntax error during pre-compilation.
static java.lang.Integer LUA_GLOBALSINDEX
           
static java.lang.Integer LUA_REGISTRYINDEX
           
static java.lang.Integer LUA_TBOOLEAN
           
static java.lang.Integer LUA_TFUNCTION
           
static java.lang.Integer LUA_TNIL
           
static java.lang.Integer LUA_TNUMBER
           
static java.lang.Integer LUA_TSTRING
           
static java.lang.Integer LUA_TTABLE
           
static java.lang.Integer LUA_TTHREAD
           
static java.lang.Integer LUA_TUSERDATA
           
 
Method Summary
 void call(int nArgs, int nResults)
           
 int checkStack(int sz)
           
 void close()
          Closes state and removes the object from the LuaStateFactory
 void concat(int n)
           
static java.lang.Number convertLuaNumber(java.lang.Double db, java.lang.Class retType)
          When you call a function in lua, it may return a number, and the number will be interpreted as a Double.
 int doBuffer(byte[] buff, java.lang.String name)
           
 int doFile(java.lang.String fileName)
           
 int doString(java.lang.String str)
           
 int equal(int idx1, int idx2)
           
 int error()
           
 long getCPtrPeer()
          Return the long representing the LuaState pointer
 void getFEnv(int idx)
           
 int getGcCount()
           
 int getGcThreshold()
           
 void getGlobal(java.lang.String global)
           
 LuaObject getLuaObject(int index)
          Creates a reference to an object in the index position of the stack
 LuaObject getLuaObject(LuaObject parent, LuaObject name)
          This constructor creates a LuaObject from a table that is indexed by any LuaObject.
 LuaObject getLuaObject(LuaObject parent, java.lang.Number name)
          This constructor creates a LuaObject from a table that is indexed by a number.
 LuaObject getLuaObject(LuaObject parent, java.lang.String name)
          Creates a reference to an object inside another object
 LuaObject getLuaObject(java.lang.String globalName)
          Creates a reference to an object in the variable globalName
 int getMetaTable(int idx)
           
 java.lang.Object getObjectFromUserdata(int idx)
          Gets a Object from Lua
 void getTable(int idx)
           
 int getTop()
           
 void insert(int idx)
           
 boolean isBoolean(int idx)
           
 boolean isCFunction(int idx)
           
 boolean isClosed()
          Returns true if state is closed.
 boolean isFunction(int idx)
           
 boolean isJavaFunction(int idx)
          Returns whether a userdata contains a Java Function
 boolean isNil(int idx)
           
 boolean isNumber(int idx)
           
 boolean isObject(int idx)
          Tells whether a lua index contains a java Object
 boolean isString(int idx)
           
 boolean isTable(int idx)
           
 boolean isUserdata(int idx)
           
 int LargError(int numArg, java.lang.String extraMsg)
           
 int LcallMeta(int obj, java.lang.String e)
           
 void LcheckAny(int nArg)
           
 double LcheckNumber(int numArg)
           
 void LcheckStack(int sz, java.lang.String msg)
           
 java.lang.String LcheckString(int numArg)
           
 void LcheckType(int nArg, int t)
           
 int lessthan(int idx1, int idx2)
           
 int LgetMetaField(int obj, java.lang.String e)
           
 void LgetMetatable(java.lang.String tName)
           
 int LgetN(int t)
           
 int LloadBuffer(byte[] buff, java.lang.String name)
           
 int LloadFile(java.lang.String fileName)
           
 int LnewMetatable(java.lang.String tName)
           
 double LoptNumber(int numArg, double def)
           
 java.lang.String LoptString(int numArg, java.lang.String def)
           
 int Lref(int t)
           
 void LsetN(int t, int n)
           
 int Ltyperror(int nArg, java.lang.String tName)
           
 void LunRef(int t, int ref)
           
 void Lwhere(int lvl)
           
 void newTable()
           
 LuaState newThread()
           
 int next(int idx)
           
 void openBase()
           
 void openBasicLibraries()
          Open lua libraries, except for loadlib and debug
 void openDebug()
           
 void openIo()
           
 void openLoadLib()
           
 void openMath()
           
 void openString()
           
 void openTable()
           
 int pcall(int nArgs, int nResults, int errFunc)
           
 void pop(int n)
           
 void pushBoolean(int bool)
           
 void pushJavaFunction(JavaFunction func)
          Pushes a JavaFunction into the state stack
 void pushJavaObject(java.lang.Object obj)
          Pushes a Java Object into the lua stack.
 void pushNil()
           
 void pushNumber(double db)
           
 void pushObjectValue(java.lang.Object obj)
          Pushes into the stack any object value.
 void pushString(byte[] bytes)
           
 void pushString(java.lang.String str)
           
 void pushValue(int idx)
           
 int rawequal(int idx1, int idx2)
           
 void rawGet(int idx)
           
 void rawGetI(int idx, int n)
           
 void rawSet(int idx)
           
 void rawSetI(int idx, int n)
           
 int ref(int t)
           
 void remove(int idx)
           
 void replace(int idx)
           
 int resume(int nArgs)
           
 int setFEnv(int idx)
           
 void setGcThreshold(int newThreshold)
           
 void setGlobal(java.lang.String name)
           
 int setMetaTable(int idx)
           
 void setTable(int idx)
           
 void setTop(int idx)
           
 int strLen(int idx)
           
 boolean toBoolean(int idx)
           
 java.lang.Object toJavaObject(int idx)
          Function that returns a Java Object equivalent to the one in the given position of the Lua Stack.
 double toNumber(int idx)
           
 java.lang.String toString(int idx)
           
 LuaState toThread(int idx)
           
 int type(int idx)
           
 java.lang.String typeName(int tp)
           
 void unRef(int t, int ref)
           
 java.lang.String version()
           
 void xmove(LuaState to, int n)
           
 int yield(int nResults)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LUA_GLOBALSINDEX

public static final java.lang.Integer LUA_GLOBALSINDEX

LUA_REGISTRYINDEX

public static final java.lang.Integer LUA_REGISTRYINDEX

LUA_TNIL

public static final java.lang.Integer LUA_TNIL

LUA_TBOOLEAN

public static final java.lang.Integer LUA_TBOOLEAN

LUA_TNUMBER

public static final java.lang.Integer LUA_TNUMBER

LUA_TSTRING

public static final java.lang.Integer LUA_TSTRING

LUA_TTABLE

public static final java.lang.Integer LUA_TTABLE

LUA_TFUNCTION

public static final java.lang.Integer LUA_TFUNCTION

LUA_TUSERDATA

public static final java.lang.Integer LUA_TUSERDATA

LUA_TTHREAD

public static final java.lang.Integer LUA_TTHREAD

LUA_ERRRUN

public static final java.lang.Integer LUA_ERRRUN
a runtime error.


LUA_ERRFILE

public static final java.lang.Integer LUA_ERRFILE

LUA_ERRSYNTAX

public static final java.lang.Integer LUA_ERRSYNTAX
syntax error during pre-compilation.


LUA_ERRMEM

public static final java.lang.Integer LUA_ERRMEM
memory allocation error. For such errors, Lua does not call the error handler function.


LUA_ERRERR

public static final java.lang.Integer LUA_ERRERR
error while running the error handler function.

Method Detail

close

public void close()
Closes state and removes the object from the LuaStateFactory


isClosed

public boolean isClosed()
Returns true if state is closed.


getCPtrPeer

public long getCPtrPeer()
Return the long representing the LuaState pointer

Returns:
long

newThread

public LuaState newThread()

getTop

public int getTop()

setTop

public void setTop(int idx)

pushValue

public void pushValue(int idx)

remove

public void remove(int idx)

insert

public void insert(int idx)

replace

public void replace(int idx)

checkStack

public int checkStack(int sz)

xmove

public void xmove(LuaState to,
                  int n)

isNumber

public boolean isNumber(int idx)

isString

public boolean isString(int idx)

isFunction

public boolean isFunction(int idx)

isCFunction

public boolean isCFunction(int idx)

isUserdata

public boolean isUserdata(int idx)

isTable

public boolean isTable(int idx)

isBoolean

public boolean isBoolean(int idx)

type

public int type(int idx)

typeName

public java.lang.String typeName(int tp)

equal

public int equal(int idx1,
                 int idx2)

rawequal

public int rawequal(int idx1,
                    int idx2)

lessthan

public int lessthan(int idx1,
                    int idx2)

toNumber

public double toNumber(int idx)

toBoolean

public boolean toBoolean(int idx)

toString

public java.lang.String toString(int idx)

strLen

public int strLen(int idx)

toThread

public LuaState toThread(int idx)

pushNil

public void pushNil()

pushNumber

public void pushNumber(double db)

pushString

public void pushString(java.lang.String str)

pushString

public void pushString(byte[] bytes)

pushBoolean

public void pushBoolean(int bool)

getTable

public void getTable(int idx)

rawGet

public void rawGet(int idx)

rawGetI

public void rawGetI(int idx,
                    int n)

newTable

public void newTable()

getMetaTable

public int getMetaTable(int idx)

getFEnv

public void getFEnv(int idx)

setTable

public void setTable(int idx)

rawSet

public void rawSet(int idx)

rawSetI

public void rawSetI(int idx,
                    int n)

setMetaTable

public int setMetaTable(int idx)

setFEnv

public int setFEnv(int idx)

call

public void call(int nArgs,
                 int nResults)

pcall

public int pcall(int nArgs,
                 int nResults,
                 int errFunc)

yield

public int yield(int nResults)

resume

public int resume(int nArgs)

getGcThreshold

public int getGcThreshold()

getGcCount

public int getGcCount()

setGcThreshold

public void setGcThreshold(int newThreshold)

version

public java.lang.String version()

next

public int next(int idx)

error

public int error()

concat

public void concat(int n)

ref

public int ref(int t)

unRef

public void unRef(int t,
                  int ref)

doFile

public int doFile(java.lang.String fileName)

doString

public int doString(java.lang.String str)

doBuffer

public int doBuffer(byte[] buff,
                    java.lang.String name)

LgetMetaField

public int LgetMetaField(int obj,
                         java.lang.String e)

LcallMeta

public int LcallMeta(int obj,
                     java.lang.String e)

Ltyperror

public int Ltyperror(int nArg,
                     java.lang.String tName)

LargError

public int LargError(int numArg,
                     java.lang.String extraMsg)

LcheckString

public java.lang.String LcheckString(int numArg)

LoptString

public java.lang.String LoptString(int numArg,
                                   java.lang.String def)

LcheckNumber

public double LcheckNumber(int numArg)

LoptNumber

public double LoptNumber(int numArg,
                         double def)

LcheckStack

public void LcheckStack(int sz,
                        java.lang.String msg)

LcheckType

public void LcheckType(int nArg,
                       int t)

LcheckAny

public void LcheckAny(int nArg)

LnewMetatable

public int LnewMetatable(java.lang.String tName)

LgetMetatable

public void LgetMetatable(java.lang.String tName)

Lwhere

public void Lwhere(int lvl)

Lref

public int Lref(int t)

LunRef

public void LunRef(int t,
                   int ref)

LgetN

public int LgetN(int t)

LsetN

public void LsetN(int t,
                  int n)

LloadFile

public int LloadFile(java.lang.String fileName)

LloadBuffer

public int LloadBuffer(byte[] buff,
                       java.lang.String name)

pop

public void pop(int n)

getGlobal

public void getGlobal(java.lang.String global)

setGlobal

public void setGlobal(java.lang.String name)

isNil

public boolean isNil(int idx)

openBase

public void openBase()

openTable

public void openTable()

openIo

public void openIo()

openString

public void openString()

openMath

public void openMath()

openDebug

public void openDebug()

openLoadLib

public void openLoadLib()

openBasicLibraries

public void openBasicLibraries()
Open lua libraries, except for loadlib and debug


getObjectFromUserdata

public java.lang.Object getObjectFromUserdata(int idx)
                                       throws LuaException
Gets a Object from Lua

Parameters:
idx - index of the lua stack
Returns:
Object
Throws:
LuaException - if the lua object does not represent a java object.

isObject

public boolean isObject(int idx)
Tells whether a lua index contains a java Object

Parameters:
idx - index of the lua stack
Returns:
boolean

pushJavaObject

public void pushJavaObject(java.lang.Object obj)
Pushes a Java Object into the lua stack.
This function does not check if the object is from a class that could be represented by a lua type. Eg: java.lang.String could be a lua string.

Parameters:
obj - Object to be pushed into lua

pushJavaFunction

public void pushJavaFunction(JavaFunction func)
                      throws LuaException
Pushes a JavaFunction into the state stack

Parameters:
func -
Throws:
LuaException

isJavaFunction

public boolean isJavaFunction(int idx)
Returns whether a userdata contains a Java Function

Parameters:
idx - index of the lua stack
Returns:
boolean

pushObjectValue

public void pushObjectValue(java.lang.Object obj)
                     throws LuaException
Pushes into the stack any object value.
This function checks if the object could be pushed as a lua type, if not pushes the java object.

Parameters:
obj -
Throws:
LuaException

toJavaObject

public java.lang.Object toJavaObject(int idx)
                              throws LuaException
Function that returns a Java Object equivalent to the one in the given position of the Lua Stack.

Parameters:
idx - Index in the Lua Stack
Returns:
Java object equivalent to the Lua one
Throws:
LuaException

getLuaObject

public LuaObject getLuaObject(java.lang.String globalName)
Creates a reference to an object in the variable globalName

Parameters:
globalName -
Returns:
LuaObject

getLuaObject

public LuaObject getLuaObject(LuaObject parent,
                              java.lang.String name)
                       throws LuaException
Creates a reference to an object inside another object

Parameters:
parent - The Lua Table or Userdata that contains the Field.
name - The name that index the field
Returns:
LuaObject
Throws:
LuaException - if parent is not a table or userdata

getLuaObject

public LuaObject getLuaObject(LuaObject parent,
                              java.lang.Number name)
                       throws LuaException
This constructor creates a LuaObject from a table that is indexed by a number.

Parameters:
parent - The Lua Table or Userdata that contains the Field.
name - The name (number) that index the field
Returns:
LuaObject
Throws:
LuaException - When the parent object isn't a Table or Userdata

getLuaObject

public LuaObject getLuaObject(LuaObject parent,
                              LuaObject name)
                       throws LuaException
This constructor creates a LuaObject from a table that is indexed by any LuaObject.

Parameters:
parent - The Lua Table or Userdata that contains the Field.
name - The name (LuaObject) that index the field
Returns:
LuaObject
Throws:
LuaException - When the parent object isn't a Table or Userdata

getLuaObject

public LuaObject getLuaObject(int index)
Creates a reference to an object in the index position of the stack

Parameters:
index - position on the stack
Returns:
LuaObject

convertLuaNumber

public static java.lang.Number convertLuaNumber(java.lang.Double db,
                                                java.lang.Class retType)
When you call a function in lua, it may return a number, and the number will be interpreted as a Double.
This function converts the number into a type specified by retType

Parameters:
db - lua number to be converted
retType - type to convert to
Returns:
The converted number