Is as the title says it is. Download LuaInterface from Here and add it to your project references.
I made this out of boredom in a few minutes because I could. If you wanted to you could likely make a text-based game or something similar.
Screenshot:
I made this out of boredom in a few minutes because I could. If you wanted to you could likely make a text-based game or something similar.
Screenshot:
Code:
using System;
using System.Reflection;
using LuaInterface;
namespace LuaConsole
{
class Program
{
private static bool running = true;
private static Lua lSEngine = new Lua();
static void Main(string[] args)
{
Console.WriteLine("Basic Lua Console\nType Help() for a list of commands.\n---\n");
Program program = new Program();
foreach (MethodInfo mInfo in program.GetType().GetMethods())
{
LuaFunctionAttribute[] FunctionAttributes = (LuaFunctionAttribute[])mInfo.GetCustomAttributes(typeof(LuaFunctionAttribute), false);
foreach(LuaFunctionAttribute fAttribute in FunctionAttributes)
{
lSEngine.RegisterFunction(fAttribute.Name, program, mInfo);
}
}
do
{
try
{
Console.Write(">");
string input = Console.ReadLine();
lSEngine.DoString(input);
}
catch (Exception e)
{
Console.WriteLine("{0} - {1}", e.GetType().Name, e.Message);
}
} while (running);
}
[LuaFunctionAttribute("Print", "Prints text to the console.")]
[LuaFunctionAttribute("Write", "Prints text to the console.")]
public void Print(string text)
{
Console.Write(text);
}
[LuaFunctionAttribute("PrintLine", "Prints text followed by a newline.")]
[LuaFunctionAttribute("WriteLine", "Prints text followed by a newline.")]
public void PrintLine(string text)
{
Console.WriteLine(text);
}
[LuaFunctionAttribute("Quit", "Quits the program.")]
public void Quit()
{
running = false;
}
[LuaFunctionAttribute("Help", "Prints a list of commands.")]
public void PrintHelp()
{
Console.WriteLine("Here is a list of commands you may use:\n---");
foreach (MethodInfo mInfo in this.GetType().GetMethods())
{
LuaFunctionAttribute[] Attributes = (LuaFunctionAttribute[])mInfo.GetCustomAttributes(typeof(LuaFunctionAttribute), false);
foreach(LuaFunctionAttribute fAttribute in Attributes)
{
Console.Write("{0}(", fAttribute.Name);
if (mInfo.GetParameters().Length > 0)
{
foreach (ParameterInfo arg in mInfo.GetParameters())
{
Console.Write("{0} {1},", arg.ParameterType.Name, arg.Name);
}
Console.Write('\b');
}
Console.WriteLine(") - {0}", fAttribute.Description);
}
}
}
[LuaFunctionAttribute("LoadScript", "Loads a Lua script to run.")]
public void LoadScript(string path)
{
try
{
lSEngine.DoFile(path);
}
catch (Exception e)
{
Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
}
}
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple=true)]
class LuaFunctionAttribute : Attribute
{
private string fName;
private string fDescription;
public LuaFunctionAttribute(string Name, string Description)
{
this.fName = Name;
this.fDescription = Description;
}
public string Name
{
get
{
return this.fName;
}
}
public string Description
{
get
{
return this.fDescription;
}
}
}
}





