Lua console - hook up lua file loading! Lua library - Added a console library with an implemented console.output(), registered all lua libraries, implemented movie.stop, movie.rerecords, movie.mode

This commit is contained in:
andres.delikat 2012-01-21 20:05:53 +00:00
parent ab9de22644
commit 955cee21b6
3 changed files with 98 additions and 20 deletions

View File

@ -12,6 +12,57 @@ namespace BizHawk.MultiClient
{ {
Lua lua = new Lua(); Lua lua = new Lua();
LuaConsole Caller; LuaConsole Caller;
public LuaImplementation(LuaConsole passed)
{
Caller = passed.get();
lua.RegisterFunction("print", this, this.GetType().GetMethod("print"));
//Register libraries
lua.NewTable("console");
for (int i = 0; i < ConsoleFunctions.Length; i++)
{
lua.RegisterFunction("console." + ConsoleFunctions[i], this, this.GetType().GetMethod("console_" + ConsoleFunctions[i]));
}
lua.NewTable("emu");
for (int i = 0; i < EmuFunctions.Length; i++)
{
lua.RegisterFunction("emu." + EmuFunctions[i], this, this.GetType().GetMethod("emu_" + EmuFunctions[i]));
}
lua.NewTable("memory");
for (int i = 0; i < MemoryFunctions.Length; i++)
{
lua.RegisterFunction("memory." + MemoryFunctions[i], this, this.GetType().GetMethod("memory_" + MemoryFunctions[i]));
}
lua.NewTable("savestate");
for (int i = 0; i < SaveStateFunctions.Length; i++)
{
lua.RegisterFunction("statestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i]));
}
lua.NewTable("movie");
for (int i = 0; i < MovieFunctions.Length; i++)
{
lua.RegisterFunction("movie." + MovieFunctions[i], this, this.GetType().GetMethod("movie_" + MovieFunctions[i]));
}
lua.NewTable("joypad");
for (int i = 0; i < JoypadFunctions.Length; i++)
{
lua.RegisterFunction("joypad." + MemoryFunctions[i], this, this.GetType().GetMethod("joypad_" + JoypadFunctions[i]));
}
}
/****************************************************/
/*************library definitions********************/
/****************************************************/
public static string[] ConsoleFunctions = new string[] {
"output"
};
public static string[] EmuFunctions = new string[] { public static string[] EmuFunctions = new string[] {
"frameadvance", "frameadvance",
"pause", "pause",
@ -53,25 +104,14 @@ namespace BizHawk.MultiClient
"set", "set",
//"get", //"get",
}; };
public LuaImplementation(LuaConsole passed)
{ /****************************************************/
Caller = passed.get(); /*************function definitions********************/
lua.RegisterFunction("print", this, this.GetType().GetMethod("print")); /****************************************************/
lua.NewTable("memory");
for (int i = 0; i < MemoryFunctions.Length; i++)
{
lua.RegisterFunction("memory." + MemoryFunctions[i], this, this.GetType().GetMethod("memory_" + MemoryFunctions[i]));
}
lua.NewTable("joypad");
for (int i = 0; i < JoypadFunctions.Length; i++)
{
lua.RegisterFunction("joypad." + MemoryFunctions[i], this, this.GetType().GetMethod("joypad_" + JoypadFunctions[i]));
}
}
public void DoLuaFile(string File) public void DoLuaFile(string File)
{ {
lua.DoFile(File);
} }
public void print(string s) public void print(string s)
{ {
@ -106,12 +146,24 @@ namespace BizHawk.MultiClient
{ {
} }
public string movie_mode()
{
return Global.MovieSession.Movie.Mode.ToString();
}
public string movie_rerecordcount() public string movie_rerecordcount()
{ {
return "No"; return Global.MovieSession.Movie.Rerecords.ToString();
} }
public void movie_stop() public void movie_stop()
{ {
Global.MovieSession.Movie.StopMovie();
}
public void console_output(object lua_input)
{
Global.MainForm.LuaConsole1.WriteToOutputWindow(lua_input.ToString());
} }
} }
} }

View File

@ -61,6 +61,7 @@ namespace BizHawk.MultiClient
public ToolBox ToolBox1 = new ToolBox(); public ToolBox ToolBox1 = new ToolBox();
public TI83KeyPad TI83KeyPad1 = new TI83KeyPad(); public TI83KeyPad TI83KeyPad1 = new TI83KeyPad();
public TAStudio TAStudio1 = new TAStudio(); public TAStudio TAStudio1 = new TAStudio();
public LuaConsole LuaConsole1 = new LuaConsole();
public MainForm(string[] args) public MainForm(string[] args)
{ {
@ -1136,6 +1137,7 @@ namespace BizHawk.MultiClient
TAStudio1.Restart(); TAStudio1.Restart();
Cheats1.Restart(); Cheats1.Restart();
ToolBox1.Restart(); ToolBox1.Restart();
LuaConsole1.Restart();
if (Global.Config.LoadCheatFileByGame) if (Global.Config.LoadCheatFileByGame)
{ {
@ -2155,7 +2157,7 @@ namespace BizHawk.MultiClient
"Disc Images", "*.cue", "Disc Images", "*.cue",
"NES", "*.nes;%ARCH%", "NES", "*.nes;%ARCH%",
"Master System", "*.sms;*.gg;*.sg;%ARCH%", "Master System", "*.sms;*.gg;*.sg;%ARCH%",
"Genesis", "*.gen;*.smd;*.bin;*.cue;%ARCH%", "Genesis", "*.gen;*.smd;*.bin;*.cue;%ARCH%",
"PC Engine", "*.pce;*.sgx;*.cue;%ARCH%", "PC Engine", "*.pce;*.sgx;*.cue;%ARCH%",
"Gameboy", "*.gb;%ARCH%", "Gameboy", "*.gb;%ARCH%",
"TI-83", "*.rom;%ARCH%", "TI-83", "*.rom;%ARCH%",
@ -2190,6 +2192,7 @@ namespace BizHawk.MultiClient
TI83KeyPad1.Restart(); TI83KeyPad1.Restart();
Cheats1.Restart(); Cheats1.Restart();
ToolBox1.Restart(); ToolBox1.Restart();
LuaConsole1.Restart();
Text = "BizHawk" + (INTERIM ? " (interim) " : ""); Text = "BizHawk" + (INTERIM ? " (interim) " : "");
HandlePlatformMenus(); HandlePlatformMenus();
StateSlots.Clear(); StateSlots.Clear();
@ -2462,8 +2465,13 @@ namespace BizHawk.MultiClient
public void OpenLuaConsole() public void OpenLuaConsole()
{ {
LuaConsole l = new LuaConsole(); if (!LuaConsole1.IsHandleCreated || LuaConsole1.IsDisposed)
l.Show(); {
LuaConsole1 = new LuaConsole();
LuaConsole1.Show();
}
else
LuaConsole1.Focus();
} }
public void OpenGameboyDebugger() public void OpenGameboyDebugger()

View File

@ -205,6 +205,18 @@ namespace BizHawk.MultiClient
} }
LuaListView.Refresh(); LuaListView.Refresh();
UpdateNumberOfScripts(); UpdateNumberOfScripts();
RunLuaScript();
}
private void RunLuaScript()
{
for (int x = 0; x < luaList.Count; x++)
{
if (luaList[x].Enabled)
{
LuaImp.DoLuaFile(luaList[x].Name);
}
}
} }
private void UpdateNumberOfScripts() private void UpdateNumberOfScripts()
@ -534,5 +546,11 @@ namespace BizHawk.MultiClient
{ {
OpenLuaFile(); OpenLuaFile();
} }
public void WriteToOutputWindow(string message)
{
OutputBox.Text += message;
OutputBox.Refresh();
}
} }
} }