Lua - implement client.GetOpenTools() to return a list of currently open tools. And client.GetTool(string name) which return an object to lua representing a currently loaded tool, lua then has access to any public methods of that object
This commit is contained in:
parent
abf1e55934
commit
8d86ee012e
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
using LuaInterface;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
@ -415,5 +416,38 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
return GlobalWin.MainForm.DesktopLocation.Y;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getopentools",
|
||||
"Returns a list of the tools currently open"
|
||||
)]
|
||||
public LuaTable GetOpenTools()
|
||||
{
|
||||
var t = Lua.NewTable();
|
||||
var tools = GlobalWin.Tools.AvailableTools.ToList();
|
||||
for (int i = 0; i < tools.Count; i++)
|
||||
{
|
||||
t[i] = tools[i].GetType().Name.ToLower();
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"gettool",
|
||||
"Returns an object that represents a currently open tool of the given name. Use getopentools to get a list of names"
|
||||
)]
|
||||
public LuaTable GetTool(string name)
|
||||
{
|
||||
var selectedTool = GlobalWin.Tools.AvailableTools
|
||||
.FirstOrDefault(tool => tool.GetType().Name.ToLower() == name.ToLower());
|
||||
|
||||
if (selectedTool != null)
|
||||
{
|
||||
return LuaHelper.ToLuaTable(Lua, selectedTool);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -319,6 +319,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
return Load<T>(false);
|
||||
}
|
||||
|
||||
public IEnumerable<IToolForm> AvailableTools
|
||||
{
|
||||
get
|
||||
{
|
||||
return _tools.Where(t => !t.IsDisposed);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateBefore()
|
||||
{
|
||||
var beforeList = _tools.Where(x => x.UpdateBefore);
|
||||
|
|
Loading…
Reference in New Issue