Fix most warnings from GCJ
[jpcrr.git] / org / jpc / luaextensions / ComponentCoding.java
bloba09ca8975f9bd9c4377a99f43ed94d2ae58c131a
1 /*
2 JPC-RR: A x86 PC Hardware Emulator
3 Release 1
5 Copyright (C) 2007-2009 Isis Innovation Limited
6 Copyright (C) 2009 H. Ilari Liusvaara
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as published by
10 the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Based on JPC x86 PC Hardware emulator,
22 A project from the Physics Dept, The University of Oxford
24 Details about original JPC can be found at:
26 www-jpc.physics.ox.ac.uk
30 package org.jpc.luaextensions;
32 import mnj.lua.*;
34 import java.io.*;
36 import org.jpc.plugins.LuaPlugin;
37 import static org.jpc.Misc.parseString;
38 import static org.jpc.Misc.encodeLine;
40 //Locking this class is used for preventing termination and when terminating.
41 public class ComponentCoding extends LuaPlugin.LuaResource
43 public void destroy()
47 private ComponentCoding(LuaPlugin plugin)
49 super(plugin);
52 public static int luaCB_decode(Lua l, LuaPlugin plugin)
54 l.pushNil();
55 try {
56 String[] x = parseString(l.checkString(1));
57 if(x != null) {
58 LuaTable tab = l.newTable();
59 for(int i = 0; i < x.length; i++)
60 l.setTable(tab, new Double(i + 1), x[i]);
61 l.push(tab);
62 } else {
63 l.pushNil();
64 l.pushNil();
65 return 2;
67 } catch(IOException e) {
68 l.pushNil();
69 l.pushString("IOException: " + e.getMessage());
70 return 2;
72 return 1;
75 public static int luaCB_encode(Lua l, LuaPlugin plugin)
77 l.pushNil();
78 int c = Lua.objLen(l.value(1));
79 if(c <= 0) {
80 l.pushBoolean(false);
81 l.pushString("Required at least one component to write.");
82 return 2;
84 Object tab = l.value(1);
85 String[] x = new String[c];
86 for(int i = 0; i < c; i++) {
87 Object obj = l.getTable(tab, new Double(i + 1));
88 if(obj instanceof String)
89 x[i] = (String)obj;
90 else
91 l.error("Can't write non-string component");
93 l.push(encodeLine(x));
94 return 1;