2 JPC-RR: A x86 PC Hardware Emulator
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
;
36 import java
.lang
.reflect
.*;
38 import org
.jpc
.plugins
.LuaPlugin
;
39 import org
.jpc
.jrsr
.*;
40 import static org
.jpc
.Misc
.parseStringToComponents
;
41 import static org
.jpc
.Misc
.errorDialog
;
42 import static org
.jpc
.Misc
.tempname
;
43 import static org
.jpc
.Misc
.nextParseLine
;
44 import static org
.jpc
.Misc
.parseString
;
45 import static org
.jpc
.Misc
.encodeLine
;
47 //Locking this class is used for preventing termination and when terminating.
48 public class TextOutFile
extends LuaPlugin
.LuaResource
50 UTFOutputLineStream object
;
52 public TextOutFile(LuaPlugin plugin
, OutputStream os
) throws IOException
55 object
= new UTFOutputLineStream(os
);
58 public void destroy() throws IOException
64 public int luaCB_write(Lua l
, LuaPlugin plugin
)
68 object
.writeLine(l
.checkString(2));
70 } catch(IOException e
) {
72 l
.pushString("IOException: " + e
.getMessage());
78 public int luaCB_write_component(Lua l
, LuaPlugin plugin
)
82 int c
= l
.objLen(l
.value(2));
85 l
.pushString("Required at least one component to write.");
88 Object tab
= l
.value(2);
89 String
[] x
= new String
[c
];
90 for(int i
= 0; i
< c
; i
++) {
91 Object obj
= l
.getTable(tab
, new Double(i
+ 1));
92 if(obj
instanceof String
)
95 l
.error("Can't write non-string component");
97 object
.encodeLine((Object
[])x
);
99 } catch(IOException e
) {
100 l
.pushBoolean(false);
101 l
.pushString("IOException: " + e
.getMessage());
107 public int luaCB_close(Lua l
, LuaPlugin plugin
)
110 plugin
.destroyLuaObject(l
);
112 } catch(IOException e
) {
113 l
.pushBoolean(false);
114 l
.pushString("IOException: " + e
.getMessage());