Added lua bitwise operators, AND, LSHIFT, RSHIFT, OR, XOR, NOT, ROTATE LEFT, ROTATE RIGHT.

This commit is contained in:
pasky1382 2012-09-02 00:56:50 +00:00
parent c91c001093
commit ff218af117
1 changed files with 305 additions and 224 deletions

View File

@ -16,15 +16,15 @@ namespace BizHawk.MultiClient
public class LuaImplementation
{
public LuaDocumentation docs = new LuaDocumentation();
Lua lua = new Lua();
LuaConsole Caller;
private Lua lua = new Lua();
private LuaConsole Caller;
public EventWaitHandle LuaWait;
public bool isRunning;
private int CurrentMemoryDomain = 0; //Main memory by default
public bool FrameAdvanceRequested;
Lua currThread;
LuaFunction savestate_registersavefunc;
LuaFunction savestate_registerloadfunc;
private Lua currThread;
private LuaFunction savestate_registersavefunc;
private LuaFunction savestate_registerloadfunc;
public void SavestateRegisterSave(string name)
{
@ -36,7 +36,8 @@ namespace BizHawk.MultiClient
}
catch (SystemException e)
{
Global.MainForm.LuaConsole1.WriteToOutputWindow("error running function attached by lua function savestate.registersave" +
Global.MainForm.LuaConsole1.WriteToOutputWindow(
"error running function attached by lua function savestate.registersave" +
"\nError message: " + e.Message);
}
}
@ -52,7 +53,8 @@ namespace BizHawk.MultiClient
}
catch (SystemException e)
{
Global.MainForm.LuaConsole1.WriteToOutputWindow("error running function attached by lua function savestate.registerload" +
Global.MainForm.LuaConsole1.WriteToOutputWindow(
"error running function attached by lua function savestate.registerload" +
"\nError message: " + e.Message);
}
}
@ -79,7 +81,8 @@ namespace BizHawk.MultiClient
lua.NewTable("console");
for (int i = 0; i < ConsoleFunctions.Length; i++)
{
lua.RegisterFunction("console." + ConsoleFunctions[i], this, this.GetType().GetMethod("console_" + ConsoleFunctions[i]));
lua.RegisterFunction("console." + ConsoleFunctions[i], this,
this.GetType().GetMethod("console_" + ConsoleFunctions[i]));
docs.Add("console", ConsoleFunctions[i], this.GetType().GetMethod("console_" + ConsoleFunctions[i]));
}
@ -107,14 +110,16 @@ namespace BizHawk.MultiClient
lua.NewTable("mainmemory");
for (int i = 0; i < MainMemoryFunctions.Length; i++)
{
lua.RegisterFunction("mainmemory." + MainMemoryFunctions[i], this, this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i]));
lua.RegisterFunction("mainmemory." + MainMemoryFunctions[i], this,
this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i]));
docs.Add("mainmemory", MainMemoryFunctions[i], this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i]));
}
lua.NewTable("savestate");
for (int i = 0; i < SaveStateFunctions.Length; i++)
{
lua.RegisterFunction("savestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
lua.RegisterFunction("savestate." + SaveStateFunctions[i], this,
this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
docs.Add("savestate", SaveStateFunctions[i], this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
}
@ -142,7 +147,8 @@ namespace BizHawk.MultiClient
lua.NewTable("client");
for (int i = 0; i < MultiClientFunctions.Length; i++)
{
lua.RegisterFunction("client." + MultiClientFunctions[i], this, this.GetType().GetMethod("client_" + MultiClientFunctions[i]));
lua.RegisterFunction("client." + MultiClientFunctions[i], this,
this.GetType().GetMethod("client_" + MultiClientFunctions[i]));
docs.Add("client", MultiClientFunctions[i], this.GetType().GetMethod("client_" + MultiClientFunctions[i]));
}
@ -153,6 +159,14 @@ namespace BizHawk.MultiClient
docs.Add("forms", FormsFunctions[i], this.GetType().GetMethod("forms_" + FormsFunctions[i]));
}
lua.NewTable("bit");
for (int i = 0; i < BitwiseFunctions.Length; i++)
{
lua.RegisterFunction("bit." + BitwiseFunctions[i], this, this.GetType().GetMethod("bit_" + BitwiseFunctions[i]));
docs.Add("bit", BitwiseFunctions[i], this.GetType().GetMethod("bit_" + BitwiseFunctions[i]));
}
docs.Sort();
}
@ -180,7 +194,9 @@ namespace BizHawk.MultiClient
{
if (color.GetType() == typeof (Double))
{
return System.Drawing.Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber));
return
System.Drawing.Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"),
System.Globalization.NumberStyles.HexNumber));
}
else
{
@ -192,6 +208,7 @@ namespace BizHawk.MultiClient
{
return new System.Drawing.SolidBrush(GetColor(color));
}
public Pen GetPen(object color)
{
return new System.Drawing.Pen(GetColor(color));
@ -204,6 +221,7 @@ namespace BizHawk.MultiClient
* variable arguments, declare them as optional and pass
* them to this method.
*/
private object[] LuaVarArgs(params object[] lua_args)
{
int n = lua_args.Length;
@ -250,6 +268,7 @@ namespace BizHawk.MultiClient
/****************************************************/
/*************library definitions********************/
/****************************************************/
public static string[] ConsoleFunctions = new string[]
{
"output",
@ -368,7 +387,8 @@ namespace BizHawk.MultiClient
//"registerread",
};
public static string[] SaveStateFunctions = new string[] {
public static string[] SaveStateFunctions = new string[]
{
"saveslot",
"loadslot",
"save",
@ -377,7 +397,8 @@ namespace BizHawk.MultiClient
"registerload",
};
public static string[] MovieFunctions = new string[] {
public static string[] MovieFunctions = new string[]
{
"mode",
"isloaded",
"rerecordcount",
@ -391,18 +412,21 @@ namespace BizHawk.MultiClient
"getinput",
};
public static string[] InputFunctions = new string[] {
public static string[] InputFunctions = new string[]
{
"get",
"getmouse",
};
public static string[] JoypadFunctions = new string[] {
public static string[] JoypadFunctions = new string[]
{
"set",
"get",
"getimmediate"
};
public static string[] MultiClientFunctions = new string[] {
public static string[] MultiClientFunctions = new string[]
{
"setwindowsize",
"openrom",
"closerom",
@ -415,7 +439,8 @@ namespace BizHawk.MultiClient
"opencheats",
};
public static string[] FormsFunctions = new string[] {
public static string[] FormsFunctions = new string[]
{
"newform",
"destroy",
"destroyall",
@ -430,6 +455,18 @@ namespace BizHawk.MultiClient
"gettext",
};
public static string[] BitwiseFunctions = new string[]
{
"band",
"lshift",
"rshift",
"rol",
"ror",
"bor",
"bxor",
"bnot",
};
/****************************************************/
/*************function definitions********************/
/****************************************************/
@ -474,7 +511,8 @@ namespace BizHawk.MultiClient
//----------------------------------------------------
//Gui library
//----------------------------------------------------
private void do_gui_text(object luaX, object luaY, object luaStr, bool alert, object background = null, object forecolor = null, object anchor = null)
private void do_gui_text(object luaX, object luaY, object luaStr, bool alert, object background = null,
object forecolor = null, object anchor = null)
{
if (!alert)
{
@ -503,10 +541,12 @@ namespace BizHawk.MultiClient
a = LuaInt(anchor);
}
}
Global.OSD.AddGUIText(luaStr.ToString(), LuaInt(luaX), LuaInt(luaY), alert, GetColor(background), GetColor(forecolor), a);
Global.OSD.AddGUIText(luaStr.ToString(), LuaInt(luaX), LuaInt(luaY), alert, GetColor(background), GetColor(forecolor),
a);
}
public void gui_text(object luaX, object luaY, object luaStr, object background = null, object forecolor = null, object anchor = null)
public void gui_text(object luaX, object luaY, object luaStr, object background = null, object forecolor = null,
object anchor = null)
{
do_gui_text(luaX, luaY, luaStr, false, background, forecolor, anchor);
}
@ -604,6 +644,7 @@ namespace BizHawk.MultiClient
}
}
}
public void gui_drawLine(object x1, object y1, object x2, object y2, object color = null)
{
using (var g = luaSurface.GetGraphics())
@ -704,7 +745,8 @@ namespace BizHawk.MultiClient
}
}
public void gui_drawPie(object X, object Y, object width, object height, object startangle, object sweepangle, object line, object background = null)
public void gui_drawPie(object X, object Y, object width, object height, object startangle, object sweepangle,
object line, object background = null)
{
using (var g = luaSurface.GetGraphics())
{
@ -1533,6 +1575,45 @@ namespace BizHawk.MultiClient
return s;
}
//----------------------------------------------------
//Bitwise Operator library
//----------------------------------------------------
public uint bit_band(uint lua_v, uint amt)
{
return lua_v & amt;
}
public uint bit_lshift(uint lua_v, int amt)
{
return lua_v << amt;
}
public uint bit_rshift(uint lua_v, int amt)
{
return lua_v >> amt;
}
public uint bit_rol(uint lua_v, int amt)
{
return (uint) ((lua_v << amt) | (lua_v >> (32 -amt)));
}
public uint bit_ror(uint lua_v, int amt)
{
return (uint) ((lua_v >> amt) | (lua_v << (32 - amt)));
}
public uint bit_bor(uint lua_v, uint amt)
{
return lua_v | amt;
}
public uint bit_bxor(uint lua_v, uint amt)
{
return lua_v ^ amt;
}
public uint bit_bnot(uint lua_v)
{
return ~ lua_v;
}
//----------------------------------------------------
//Savestate library
//----------------------------------------------------