Lua: Make console.log(...) a little more prettier.

This commit is contained in:
gochaism 2014-05-01 00:25:14 +00:00
parent acc124ca99
commit a84b4126f2
2 changed files with 47 additions and 35 deletions

View File

@ -41,8 +41,45 @@ namespace BizHawk.Client.EmuHawk
)]
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)
{
GlobalWin.Tools.LuaConsole.WriteToOutputWindow("NULL");
@ -86,32 +123,7 @@ namespace BizHawk.Client.EmuHawk
}
}
}
}
[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);
GlobalWin.Tools.LuaConsole.WriteToOutputWindow(terminator);
}
}
}

View File

@ -1,9 +1,9 @@
--console.clear()
--console.writeline("--cleared previous output")
--console.log("--Logging ", "multiple ", "values ", "in one ", "call", "\n")
--console.write("--console.write does not include a new line")
--console.writeline("--but console.writeline does")
--console.writeline("--next line")
--print("--Print Single value\n")
--console.writeline("--Log a lua table:")
console.clear()
console.writeline("--cleared previous output")
console.log("--Logging", "multiple", "values", "in one", "call")
console.write("--console.write does not include a new line")
console.writeline("--but console.writeline does")
console.writeline("--next line", "--next line")
print("--Print Single value")
console.writeline("--Log a lua table:")
console.log(joypad.get())