Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
tuler committed Jun 10, 2005
1 parent 4b666c4 commit d0c6478
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 93 deletions.
3 changes: 1 addition & 2 deletions doc/us/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ <h1>LuaJava</h1>
<li><a href="manual.html">Manual</a>
<ul>
<li><a href="manual.html#luareference">Lua Reference</a></li>
<li><a href="manual.html#fromjava">Use from Java</a></li>
<li><a href="API/index.html">Java Reference</a></li>
</ul>
</li>
<li><strong>Examples</strong></li>
<li><a href="API/index.html">Java Reference</a></li>
<li><a href="history.html">History</a></li>
<li><a href="license.html">License</a></li>
</ul>
Expand Down
3 changes: 1 addition & 2 deletions doc/us/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ <h1>LuaJava</h1>
<li><a href="manual.html">Manual</a>
<ul>
<li><a href="manual.html#luareference">Lua Reference</a></li>
<li><a href="manual.html#fromjava">Use from Java</a></li>
<li><a href="API/index.html">Java Reference</a></li>
</ul>
</li>
<li><a href="examples.html">Examples</a></li>
<li><a href="API/index.html">Java Reference</a></li>
<li><strong>History</strong></li>
<li><a href="license.html">License</a></li>
</ul>
Expand Down
3 changes: 1 addition & 2 deletions doc/us/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ <h1>LuaJava</h1>
<li><a href="manual.html">Manual</a>
<ul>
<li><a href="manual.html#luareference">Lua Reference</a></li>
<li><a href="manual.html#fromjava">Use from Java</a></li>
<li><a href="API/index.html">Java Reference</a></li>
</ul>
</li>
<li><a href="examples.html">Examples</a></li>
<li><a href="API/index.html">Java Reference</a></li>
<li><a href="history.html">History</a></li>
<li><a href="license.html">License</a></li>
</ul>
Expand Down
3 changes: 1 addition & 2 deletions doc/us/license.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ <h1>LuaJava</h1>
<li><a href="manual.html">Manual</a>
<ul>
<li><a href="manual.html#luareference">Lua Reference</a></li>
<li><a href="manual.html#fromjava">Use from Java</a></li>
<li><a href="API/index.html">Java Reference</a></li>
</ul>
</li>
<li><a href="examples.html">Examples</a></li>
<li><a href="API/index.html">Java Reference</a></li>
<li><a href="history.html">History</a></li>
<li><strong>License</strong></li>
</ul>
Expand Down
65 changes: 1 addition & 64 deletions doc/us/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ <h1>LuaJava</h1>
<li><strong>Manual</strong>
<ul>
<li><a href="manual.html#luareference">Lua Reference</a></li>
<li><a href="manual.html#fromjava">Use from Java</a></li>
<li><a href="API/index.html">Java Reference</a></li>
</ul>
</li>
<li><a href="examples.html">Examples</a></li>
<li><a href="API/index.html">Java Reference</a></li>
<li><a href="history.html">History</a></li>
<li><a href="license.html">License</a></li>
</ul>
Expand Down Expand Up @@ -199,68 +198,6 @@ <h2><a name="luareference"></a>Lua Reference</h2>

</dl>

<h2><a name="fromjava"></a>How to use LuaJava from Java</h2>

<p>Since Java is a compiled and typed language, the usage of scripting languages can be very useful. We have seen how to write Lua code using Java objects.
</p>
<p>Now we are going to see how to use Lua objects and proxies in Java.</p>


<h3>LuaState</h3>

<p>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.</p>

<h3>LuaObject</h3>

<p>LuaJava has a class <code>org.keplerproject.luajava.LuaObject</code>. This class represents a Lua object of any type. A LuaObject is constructed by the LuaState object by the overloaded <code>getLuaObject</code> function.
There are four ways in which you can create a LuaObject.</p>

<dl>
<dt><strong><code>public LuaObject getLuaObject(String globalName);</code></strong></dt>
<dd><code>globalName</code> is the name of the global variable that hold the wanted object.</dd>

<dt><strong><code>public LuaObject getLuaObject(LuaObject parent, String name);</code></strong></dt>
<dd>
<code>parent</code> is the LuaObject representing the parent object. The parent object should be either a table or userdata.<br/>
<code>name</code> is the index name of the wanted object.
</dd>

<dt><strong><code>public LuaObject getLuaObject(LuaObject parent, Number name);</code></strong></dt>
<dd>
<code>parent</code> is the LuaObject representing the parent object. The parent object should be either a table or userdata.<br/>
<code>name</code> is the numeric index of the wanted object.
</dd>

<dt><strong><code>LuaObject getLuaObject(LuaObject parent, LuaObject name);</code></strong></dt>
<dd>
<code>parent</code> is the LuaObject representing the parent object. The parent object should be either a table or userdata.<br/>
<code>name</code> is the the object that the wanted object is indexed by.
</dd>

<dt><strong><code>public LuaObject getLuaObject(int index);</code></strong></dt>
<dd>
<code>index</code> is the index of the object in the Lua stack. The constructor will not pop the object from the stack.
</dd>
</dl>

<p>The LuaObject will represent only the object itself, not a variable or a stack index, so when you change a string, remember that strings are immutable objects in Lua, and the LuaObject you have will represent the old one.</p>


<h3>Proxies</h3>

<p>LuaJava allows you to implement a class in Lua, like said before. If you want to create this proxy from Java, you should have a LuaObject representing the table that has the functions that implement the interface. From this LuaObject you can call the <code>createProxy(String implements)</code>. This method receives the string with the name of the interfaces implemented by the object separated by comma.</p>


<h3>JavaFunction</h3>

<p>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 <code>execute</code> method. This <code>execute</code> method is the method that will be called when you call the function from Lua.

To register the JavaFunction in Lua use the method <code>register(String name)</code>.
</p>


</div> <!-- id="content" -->

</div> <!-- id="main" -->
Expand Down
9 changes: 5 additions & 4 deletions src/java/org/keplerproject/luajava/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@
import java.io.InputStreamReader;

/**
* LuaJava console
* Simple LuaJava console.
* This is also an example on how to use the Java side of LuaJava and how to startup
* a LuaJava application.
*
* @author Thiago Ponte
*/
public class Console
{

/**
* Creates a console for user interaction
* Creates a console for user interaction.
*
* @param args -
* names of the lua files to be executed
* @param args names of the lua files to be executed
*/
public static void main(String[] args)
{
Expand Down
16 changes: 8 additions & 8 deletions src/java/org/keplerproject/luajava/JavaFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
package org.keplerproject.luajava;

/**
* This interface represents a `function' that can be called from Lua. Any
* object that implements this interface can be passed as a function to Lua.
* The method <code>foo</code> is called when Lua tries to execute the
* function.
* 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 <code>execute</code> method. This <code>execute</code>
* method is the method that will be called when you call the function from Lua.
* To register the JavaFunction in Lua use the method <code>register(String name)</code>.
*/
public abstract class JavaFunction
{
Expand All @@ -47,8 +48,8 @@ public abstract class JavaFunction
public abstract int execute() throws LuaException;

/**
* Constructor that receives the current LuaState.
* @param L
* Constructor that receives a LuaState.
* @param L LuaState object associated with this JavaFunction object
*/
public JavaFunction(LuaState L)
{
Expand All @@ -71,7 +72,7 @@ public LuaObject getParam(int idx)
/**
* Register a JavaFunction with a given name. This method registers in a
* global variable the JavaFunction specified.
* @param name The name of the function.
* @param name name of the function.
*/
public void register(String name) throws LuaException
{
Expand All @@ -82,4 +83,3 @@ public void register(String name) throws LuaException
}
}
}

24 changes: 23 additions & 1 deletion src/java/org/keplerproject/luajava/LuaObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,29 @@
import java.util.StringTokenizer;

/**
* Class that represents a Lua Object.
* This class represents a Lua object of any type.
* A LuaObject is constructed by a {@link LuaState} object using one of the four methods:
* <ul>
* <li>{@link LuaState#getLuaObject(String globalName)}</li>
* <li>{@link LuaState#getLuaObject(LuaObject parent, String name)}</li>
* <li>{@link LuaState#getLuaObject(LuaObject parent, Number name)}</li>
* <li>{@link LuaState#getLuaObject(LuaObject parent, LuaObject name)}</li>
* <li>{@link LuaState#getLuaObject(int index)}</li>
* </ul>
* The LuaObject will represent only the object itself, not a variable or a
* stack index, so when you change a string, remember that strings are
* immutable objects in Lua, and the LuaObject you have will represent the
* old one.
*
* <h2>Proxies</h2>
*
* LuaJava allows you to implement a class in Lua, like said before.
* If you want to create this proxy from Java, you should have a LuaObject
* representing the table that has the functions that implement the interface.
* From this LuaObject you can call the <code>createProxy(String implements)</code>.
* This method receives the string with the name of the interfaces implemented by
* the object separated by comma.
*
* @author Rizzato
* @author Thiago Ponte
*/
Expand Down
34 changes: 26 additions & 8 deletions src/java/org/keplerproject/luajava/LuaState.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
package org.keplerproject.luajava;

/**
* Class that represents a lua state. This class gives access to all
* lua's functions and some of LuaJava's functions implemented in C.
* 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.
* @author Thiago Ponte
*/
public class LuaState
Expand All @@ -47,10 +49,30 @@ public class LuaState
/*
* error codes for `lua_load' and `lua_pcall'
*/
/**
* a runtime error.
*/
final public static Integer LUA_ERRRUN = new Integer(1);

/**
*
*/
final public static Integer LUA_ERRFILE = new Integer(2);

/**
* syntax error during pre-compilation.
*/
final public static Integer LUA_ERRSYNTAX = new Integer(3);

/**
* memory allocation error. For such errors, Lua does not call
* the error handler function.
*/
final public static Integer LUA_ERRMEM = new Integer(4);

/**
* error while running the error handler function.
*/
final public static Integer LUA_ERRERR = new Integer(5);

/**
Expand All @@ -72,9 +94,7 @@ public class LuaState
protected LuaState(int stateId)
{
luaState = _open();

luajava_open(luaState, stateId);

this.stateId = stateId;
}

Expand All @@ -85,9 +105,7 @@ protected LuaState(int stateId)
protected LuaState(CPtr luaState)
{
this.luaState = luaState;

this.stateId = LuaStateFactory.insertLuaState(this);

luajava_open(luaState, stateId);
}

Expand Down Expand Up @@ -936,8 +954,8 @@ public LuaObject getLuaObject(String globalName)

/**
* Creates a reference to an object inside another object
* @param parent The Lua Table or Userdata that contains the Field.
* @param name The name that index the field
* @param parent The Lua Table or Userdata that contains the Field.
* @param name The name that index the field
* @return LuaObject
* @throws LuaException if parent is not a table or userdata
*/
Expand Down
48 changes: 48 additions & 0 deletions src/java/org/keplerproject/luajava/package.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
$Id: package.html,v 1.1 2005-06-10 19:44:53 tuler Exp $
Copyright (C) 2005 Kepler Project
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
</head>
<body bgcolor="white">

##### THIS IS THE TEMPLATE FOR THE PACKAGE DOC COMMENTS. #####
##### TYPE YOUR PACKAGE COMMENTS HERE. BEGIN WITH A #####
##### ONE-SENTENCE SUMMARY STARTING WITH A VERB LIKE: #####
Provides for....


<h2>Related Documentation</h2>

For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="http://www.keplerproject.org/luajava">LuaJava</a>
<li><a href="http://www.lua.org">Lua</a>
</ul>

<!-- Put @see and @since tags down here. -->

</body>
</html>

0 comments on commit d0c6478

Please sign in to comment.