2014-05-21 00:17:35 +00:00
using System ;
2013-10-31 23:55:17 +00:00
2017-07-10 04:51:02 +00:00
using NLua ;
2013-10-28 19:13:01 +00:00
2019-12-14 17:59:21 +00:00
using BizHawk.Client.Common ;
2013-11-03 03:54:37 +00:00
namespace BizHawk.Client.EmuHawk
2013-10-28 19:13:01 +00:00
{
2019-12-14 17:59:21 +00:00
public sealed class InputLuaLibrary : DelegatingLuaLibraryEmu
2013-10-28 19:13:01 +00:00
{
2013-10-31 13:07:42 +00:00
public InputLuaLibrary ( Lua lua )
2014-05-21 00:17:35 +00:00
: base ( lua ) { }
public InputLuaLibrary ( Lua lua , Action < string > logOutputCallback )
: base ( lua , logOutputCallback ) { }
2013-10-31 13:07:42 +00:00
2017-05-19 14:47:18 +00:00
public override string Name = > "input" ;
2013-10-31 13:07:42 +00:00
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local nlinpget = input.get( );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("get", "Returns a lua table of all the buttons the user is currently pressing on their keyboard and gamepads\nAll buttons that are pressed have their key values set to true; all others remain nil.")]
2014-01-26 13:30:45 +00:00
public LuaTable Get ( )
2013-10-28 19:13:01 +00:00
{
2019-12-14 17:59:21 +00:00
var result = APIs . Input . Get ( ) ;
var table = Lua . NewTable ( ) ;
foreach ( var kvp in result ) table [ kvp . Key ] = kvp . Value ;
return table ;
2013-10-28 19:13:01 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local nlinpget = input.getmouse( );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("getmouse", "Returns a lua table of the mouse X/Y coordinates and button states. Table keys are X, Y, Left, Middle, Right, XButton1, XButton2, Wheel.")]
2014-01-26 13:30:45 +00:00
public LuaTable GetMouse ( )
2013-10-28 19:13:01 +00:00
{
2019-12-14 17:59:21 +00:00
var result = APIs . Input . GetMouse ( ) ;
var table = Lua . NewTable ( ) ;
foreach ( var kvp in result ) table [ kvp . Key ] = kvp . Value ;
return table ;
2013-10-28 19:13:01 +00:00
}
}
}