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 java.io.FileNotFoundException;
27: import java.io.IOException;
28:
29: import org.keplerproject.luajava.LuaException;
30: import org.keplerproject.luajava.LuaObject;
31: import org.keplerproject.luajava.LuaState;
32: import org.keplerproject.luajava.LuaStateFactory;
33:
34: public class Main {
35:
36: static String str = "a = 'campo a';"
37: + "b = 'campo b';"
38: + "c = 'campo c';"
39: + "tab= { a='tab a'; b='tab b'; c='tab c', d={ e='tab d e'} } ;"
40: + "function imprime (str) print(str); return 'joao', 1 end;"
41: + "luaPrint={implements='org.keplerproject.luajava.test.Printable', print=function(str)print('Printing from lua :'..str)end }";
42:
43: public static void main(String[] main_args) throws IOException,
44: FileNotFoundException, ClassNotFoundException, LuaException {
45: LuaState L = LuaStateFactory.newLuaState();
46: L.openBase();
47:
48: L.LdoString(str);
49:
50: LuaObject func = L.getLuaObject("imprime");
51: Object[] teste = func.call(new Object[] { "TESTANDO" }, 2);
52: System.out.println(teste[0]);
53: System.out.println(teste[1]);
54:
55: System.out.println("PROXY TEST :");
56: Printable p = new ObjPrint();
57: p.print("TESTE 1");
58:
59: LuaObject o = L.getLuaObject("luaPrint");
60: p = (Printable) o
61: .createProxy("org.keplerproject.luajava.test.Printable");
62: p.print("Teste 2");
63:
64: L.close();
65: }
66: }
|