Fix most warnings from GCJ
[jpcrr.git] / org / jpc / luaextensions / TextOutFile.java
blob67de246d13e9b0b24daf92206003445016b45c8f
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 org.jpc.jrsr.*;
39 //Locking this class is used for preventing termination and when terminating.
40 public class TextOutFile extends LuaPlugin.LuaResource
42 UTFOutputLineStream object;
44 public TextOutFile(LuaPlugin plugin, OutputStream os) throws IOException
46 super(plugin);
47 object = new UTFOutputLineStream(os);
50 public void destroy() throws IOException
52 object.close();
53 object = null;
56 public int luaCB_write(Lua l, LuaPlugin plugin)
58 l.pushNil();
59 try {
60 object.writeLine(l.checkString(2));
61 l.pushBoolean(true);
62 } catch(IOException e) {
63 l.pushBoolean(false);
64 l.pushString("IOException: " + e.getMessage());
65 return 2;
67 return 1;
70 public int luaCB_write_component(Lua l, LuaPlugin plugin)
72 l.pushNil();
73 try {
74 int c = Lua.objLen(l.value(2));
75 if(c <= 0) {
76 l.pushBoolean(false);
77 l.pushString("Required at least one component to write.");
78 return 2;
80 Object tab = l.value(2);
81 String[] x = new String[c];
82 for(int i = 0; i < c; i++) {
83 Object obj = l.getTable(tab, new Double(i + 1));
84 if(obj instanceof String)
85 x[i] = (String)obj;
86 else
87 l.error("Can't write non-string component");
89 object.encodeLine((Object[])x);
90 l.pushBoolean(true);
91 } catch(IOException e) {
92 l.pushBoolean(false);
93 l.pushString("IOException: " + e.getMessage());
94 return 2;
96 return 1;
99 public int luaCB_close(Lua l, LuaPlugin plugin)
101 try {
102 plugin.destroyLuaObject(l);
103 l.pushBoolean(true);
104 } catch(IOException e) {
105 l.pushBoolean(false);
106 l.pushString("IOException: " + e.getMessage());
107 return 2;
109 return 1;