org.keplerproject.luajava
Class JavaFunction

java.lang.Object
  extended by org.keplerproject.luajava.JavaFunction

public abstract class JavaFunction
extends java.lang.Object

JavaFunction is a class that can be used to implement a Lua function in Java. JavaFunction is an abstract class, so in order to use it you must extend this class and implement the execute method. This execute method is the method that will be called when you call the function from Lua. To register the JavaFunction in Lua use the method register(String name).


Constructor Summary
JavaFunction(LuaState L)
          Constructor that receives a LuaState.
 
Method Summary
abstract  int execute()
          This method is called from Lua.
 LuaObject getParam(int idx)
          Returns a parameter received from Lua.
 void register(java.lang.String name)
          Register a JavaFunction with a given name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaFunction

public JavaFunction(LuaState L)
Constructor that receives a LuaState.

Parameters:
L - LuaState object associated with this JavaFunction object
Method Detail

execute

public abstract int execute()
                     throws LuaException
This method is called from Lua. Any parameters can be taken with getParam. A reference to the JavaFunctionWrapper itself is always the first parameter received. Values passed back as results of the function must be pushed onto the stack.

Returns:
The number of values pushed onto the stack.
Throws:
LuaException

getParam

public LuaObject getParam(int idx)
Returns a parameter received from Lua. Parameters are numbered from 1. A reference to the JavaFunction itself is always the first parameter received (the same as this).

Parameters:
idx - Index of the parameter.
Returns:
Reference to parameter.
See Also:
LuaObject

register

public void register(java.lang.String name)
              throws LuaException
Register a JavaFunction with a given name. This method registers in a global variable the JavaFunction specified.

Parameters:
name - name of the function.
Throws:
LuaException