Lua: Make console.log(...) a little more prettier.
This commit is contained in:
parent
acc124ca99
commit
a84b4126f2
|
@ -41,8 +41,45 @@ namespace BizHawk.Client.EmuHawk
|
||||||
)]
|
)]
|
||||||
public static void Log(params object[] outputs)
|
public static void Log(params object[] outputs)
|
||||||
{
|
{
|
||||||
foreach (var output in outputs)
|
LogWithSeparator("\t", "\n", outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single param version is used by logOutputCallback of some libraries.
|
||||||
|
public static void Log(string output)
|
||||||
{
|
{
|
||||||
|
Log((object)output);
|
||||||
|
}
|
||||||
|
|
||||||
|
[LuaMethodAttributes(
|
||||||
|
"writeline",
|
||||||
|
"Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable"
|
||||||
|
)]
|
||||||
|
public static void WriteLine(params object[] outputs)
|
||||||
|
{
|
||||||
|
LogWithSeparator("\n", "\n", outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
[LuaMethodAttributes(
|
||||||
|
"write",
|
||||||
|
"Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable"
|
||||||
|
)]
|
||||||
|
public static void Write(params object[] outputs)
|
||||||
|
{
|
||||||
|
LogWithSeparator(string.Empty, string.Empty, outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable
|
||||||
|
private static void LogWithSeparator(string separator, string terminator, params object[] outputs)
|
||||||
|
{
|
||||||
|
for (var outIndex = 0; outIndex < outputs.Length; outIndex++)
|
||||||
|
{
|
||||||
|
var output = outputs[outIndex];
|
||||||
|
|
||||||
|
if (outIndex != 0)
|
||||||
|
{
|
||||||
|
GlobalWin.Tools.LuaConsole.WriteToOutputWindow(separator);
|
||||||
|
}
|
||||||
|
|
||||||
if (output == null)
|
if (output == null)
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.LuaConsole.WriteToOutputWindow("NULL");
|
GlobalWin.Tools.LuaConsole.WriteToOutputWindow("NULL");
|
||||||
|
@ -86,32 +123,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
GlobalWin.Tools.LuaConsole.WriteToOutputWindow(terminator);
|
||||||
|
|
||||||
[LuaMethodAttributes(
|
|
||||||
"writeline",
|
|
||||||
"Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable"
|
|
||||||
)]
|
|
||||||
public static void WriteLine(params object[] outputs)
|
|
||||||
{
|
|
||||||
Log(outputs);
|
|
||||||
Log('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
[LuaMethodAttributes(
|
|
||||||
"write",
|
|
||||||
"Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable"
|
|
||||||
)]
|
|
||||||
public static void Write(params object[] outputs)
|
|
||||||
{
|
|
||||||
Log(outputs);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Single param version is used by logOutputCallback of some libraries.
|
|
||||||
public static void Log(string output)
|
|
||||||
{
|
|
||||||
var outputs = new[] { output };
|
|
||||||
Log(outputs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
--console.clear()
|
console.clear()
|
||||||
--console.writeline("--cleared previous output")
|
console.writeline("--cleared previous output")
|
||||||
--console.log("--Logging ", "multiple ", "values ", "in one ", "call", "\n")
|
console.log("--Logging", "multiple", "values", "in one", "call")
|
||||||
--console.write("--console.write does not include a new line")
|
console.write("--console.write does not include a new line")
|
||||||
--console.writeline("--but console.writeline does")
|
console.writeline("--but console.writeline does")
|
||||||
--console.writeline("--next line")
|
console.writeline("--next line", "--next line")
|
||||||
--print("--Print Single value\n")
|
print("--Print Single value")
|
||||||
--console.writeline("--Log a lua table:")
|
console.writeline("--Log a lua table:")
|
||||||
console.log(joypad.get())
|
console.log(joypad.get())
|
||||||
|
|
Loading…
Reference in New Issue