- twiggery_ver_0_5_2.zip
- Examples
- eg_01 [hello world].twg
- eg_02 [if-elseif-else].twg
- eg_03 [for-to-step].twg
- eg_04 [while, do-while].twg
- eg_05 [search prime].twg
- eg_06 [calculate PI].twg
- eg_07 [using plugins].twg
- eg_08 [IO plugin test].twg
- eg_09 [Graphics plugin test].twg
- eg_10 [pong].twg
- eg_11 [calculator].twg
- eg_12 [image].twg
- media
- ding.wav
- sprite.bmp
- Histroy.txt
- IDE
- CodeLeaf.exe
- Plugins
- Twiggery.dll
- License.txt
- Programming_with_Twiggery.pdf
- Source
- CodeLeaf
- Plugin
- Audio
- Core
- Graphics
- IO
- Math
- Test
- Twiggery.sln
- Twiggery.suo
- Twiggery
- TDK
- ShellCpp
- release
- ts.exe
- TVM_Win32.dll
- TVM_Win32.exp
- TVM_Win32.lib
- TVM_Win32.sln
- TVM_Win32.suo
- TVM_Win32
- TVM_Win32_Test
- ShellDotNet
- ShellJava
- build.xml
- dist
- js.jar
- manifest.mf
- nbproject
- src
- javaapplication
- Twiggery
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Threading;
using num = System.Single;
using arguments = System.Collections.Generic.List<object>;
namespace Twiggery.Plugin.IO
{
public class IO
{
internal class FileAttrib
{
public FileStream fileStream = null;
public StreamReader streamReader = null;
public StreamWriter streamWriter = null;
public FileAttrib(FileStream fs, StreamWriter sw)
{
fileStream = fs;
streamWriter = sw;
}
public FileAttrib(FileStream fs, StreamReader sr)
{
fileStream = fs;
streamReader = sr;
}
public FileAttrib(FileStream fs, StreamReader sr, StreamWriter sw)
{
fileStream = fs;
streamReader = sr;
streamWriter = sw;
}
public void Close()
{
if (null != streamWriter)
{
streamWriter.Close();
}
if (null != streamReader)
{
streamReader.Close();
}
if (null != fileStream)
{
fileStream.Close();
}
}
}
private static int idf = 0;
private static Dictionary<int, FileAttrib> files = new Dictionary<int, FileAttrib>();
public static void openFile(arguments args)
{
string access = (string)args[0];
string name = (string)args[1];
args.Clear();
num result = (num)(-1);
switch (access)
{
case "rw":
{
FileStream fs = new FileStream(name, FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
StreamReader sr = new StreamReader(fs);
FileAttrib fa = new FileAttrib(fs, sw);
fa.streamReader = sr;
files[++idf] = fa;
result = (num)idf;
}
break;
case "w":
{
FileStream fs = new FileStream(name, FileMode.OpenOrCreate, FileAccess.Write);
fs.Close();
fs = new FileStream(name, FileMode.Truncate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
FileAttrib fa = new FileAttrib(fs, sw);
files[++idf] = fa;
result = (num)idf;
}
break;
case "r":
{
FileStream fs = new FileStream(name, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
FileAttrib fa = new FileAttrib(fs, sr);
files[++idf] = fa;
result = (num)idf;
}
break;
default:
throw new Exception("Invalid file access option " + access);
}
args.Add(result);
}
private static void closeFile(arguments args)
{
int id = (int)(num)args[0];
if (files.ContainsKey(id))
{
FileAttrib fa = files[id];
fa.Close();
files.Remove(id);
}
}
private static void writeFile(arguments args)
{
int id = (int)(num)args[args.Count - 1];
if (files.ContainsKey(id))
{
FileAttrib fa = files[id];
args.RemoveAt(args.Count - 1);
for (int i = args.Count - 1; i >= 0; i--)
{
object obj = args[i];
if (obj.Equals("\\n"))
{
obj = "\r\n";
}
fa.streamWriter.Write(obj);
}
args.Clear();
}
}
public static void readFile(arguments args)
{
int count = 0;
int start = 0;
int id = 0;
if (args.Count == 3)
{
count = (int)(num)args[0];
start = (int)(num)args[1];
id = (int)(num)args[2];
}
else if (args.Count == 1)
{
count = -1;
start = -1;
id = (int)(num)args[0];
}
else
{
throw new Exception("Invalid read file arguments");
}
args.Clear();
if (files.ContainsKey(id))
{
FileAttrib fa = files[id];
if (null != fa.streamReader)
{
string str_buf = null;
if (-1 == count)
{
str_buf = fa.streamReader.ReadLine();
}
else
{
char[] buffer = new char[count];
fa.streamReader.Read(buffer, start, count);
str_buf = new string(buffer);
}
num result = num.Parse(str_buf);
args.Add(result);
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.