01: /*
02: * Copyright (C) 2003-2007 Kepler Project.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining
05: * a copy of this software and associated documentation files (the
06: * "Software"), to deal in the Software without restriction, including
07: * without limitation the rights to use, copy, modify, merge, publish,
08: * distribute, sublicense, and/or sell copies of the Software, and to
09: * permit persons to whom the Software is furnished to do so, subject to
10: * the following conditions:
11: *
12: * The above copyright notice and this permission notice shall be
13: * included in all copies or substantial portions of the Software.
14: *
15: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20: * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21: * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22: */
23:
24: package org.keplerproject.luajava.test;
25:
26: import org.keplerproject.luajava.JavaFunction;
27: import org.keplerproject.luajava.LuaException;
28: import org.keplerproject.luajava.LuaState;
29: import org.keplerproject.luajava.LuaStateFactory;
30:
31: public class TestClass {
32: public final LuaState Lf;
33:
34: public JavaFunction jf;
35:
36: public TestClass(LuaState L) {
37: this .Lf = L;
38:
39: jf = new JavaFunction(L) {
40: public int execute() {
41: this .L.pushString("Returned String");
42: System.out.println("Printing from Java Function");
43: return 1;
44: }
45: };
46: }
47:
48: public static void main(String[] args) throws LuaException {
49: LuaState L = LuaStateFactory.newLuaState();
50: L.openBase();
51:
52: TestClass test = new TestClass(L);
53:
54: test.jf.register("javaFuncTest");
55:
56: test.Lf.LdoString(" f=javaFuncTest(); print(f) ");
57:
58: L.close();
59: }
60:
61: }
|