More lua functions.

This commit is contained in:
kylethomson 2011-02-20 20:14:55 +00:00
parent 5172f9e397
commit 7430a35806
2 changed files with 30 additions and 2 deletions

View File

@ -12,10 +12,17 @@ namespace BizHawk.MultiClient
{
Lua lua = new Lua();
LuaWindow Caller;
public static string[] MemoryFunctions = new string[] {
"readbyte",
"writebyte"};
public LuaImplementation(LuaWindow passed)
{
Caller = passed.get();
lua.RegisterFunction("print",this, this.GetType().GetMethod("print"));
for (int i = 0; i < MemoryFunctions.Length; i++)
{
lua.RegisterFunction(MemoryFunctions[i], this, this.GetType().GetMethod(MemoryFunctions[i]));
}
}
public void DoLuaFile(string File)
{
@ -23,7 +30,28 @@ namespace BizHawk.MultiClient
}
public void print(string s)
{
Caller.AddText(s);
Caller.AddText(string.Format(s));
}
public string readbyte(object lua_input)
{
byte x;
if (lua_input.GetType() == typeof(string))
{
x = Global.Emulator.MainMemory.PeekByte(int.Parse((string)lua_input));
return x.ToString();
}
else
{
double y = (double)lua_input;
x = Global.Emulator.MainMemory.PeekByte(Convert.ToInt32(y));
return x.ToString();
}
}
public void writebyte(object lua_input)
{
Global.Emulator.MainMemory.PokeByte((int)lua_input, (byte)lua_input);
}
}
}

View File

@ -26,7 +26,7 @@ namespace BizHawk.MultiClient.tools
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Open Lua Script";
fdlg.InitialDirectory = @"c:\"; //Switch this to a better default directory
fdlg.InitialDirectory = @".\"; //Switch this to a better default directory
fdlg.Filter = "Lua files (*.lua)|*.lua|All files (*.*)|*.*";
fdlg.FilterIndex = 1;
fdlg.RestoreDirectory = true;