More basic prep.
TSHOCKPLUGINS-4
This commit is contained in:
parent
c45291eb6b
commit
15d9a2aa8c
1 changed files with 46 additions and 3 deletions
|
|
@ -11,19 +11,45 @@ namespace TShockAPI.LuaSystem
|
|||
{
|
||||
private Lua Lua = null;
|
||||
public string LuaPath = "";
|
||||
public string LuaAutorunPath = "";
|
||||
public LuaLoader(string path)
|
||||
{
|
||||
Lua = new Lua();
|
||||
LuaPath = path;
|
||||
LuaAutorunPath = Path.Combine(LuaPath, "autorun");
|
||||
SendLuaDebugMsg("Lua 5.1 (serverside) initialized.");
|
||||
|
||||
if (!Directory.Exists(LuaPath))
|
||||
{
|
||||
Directory.CreateDirectory(LuaPath);
|
||||
Directory.CreateDirectory(LuaAutorunPath);
|
||||
}
|
||||
|
||||
RegisterLuaFunctions();
|
||||
LoadServerAutoruns();
|
||||
}
|
||||
|
||||
public void LoadServerAutoruns()
|
||||
{
|
||||
foreach (string s in Directory.GetFiles(Path.Combine(LuaPath, "autorun")))
|
||||
try
|
||||
{
|
||||
Lua.DoFile(s);
|
||||
SendLuaDebugMsg("Loaded file: " + s);
|
||||
foreach (string s in Directory.GetFiles(LuaAutorunPath))
|
||||
{
|
||||
SendLuaDebugMsg("Loading: " + s);
|
||||
try
|
||||
{
|
||||
Lua.DoFile(s);
|
||||
}
|
||||
catch (LuaException e)
|
||||
{
|
||||
SendLuaDebugMsg(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SendLuaDebugMsg(e.Message);
|
||||
SendLuaDebugMsg(e.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -34,5 +60,22 @@ namespace TShockAPI.LuaSystem
|
|||
Console.WriteLine("Lua: " + s);
|
||||
Console.ForegroundColor = previousColor;
|
||||
}
|
||||
|
||||
public void RegisterLuaFunctions()
|
||||
{
|
||||
LuaFunctions LuaFuncs = new LuaFunctions();
|
||||
Lua.RegisterFunction("Print", LuaFuncs, LuaFuncs.GetType().GetMethod("Print"));
|
||||
}
|
||||
}
|
||||
|
||||
public class LuaFunctions
|
||||
{
|
||||
public void Print(string s)
|
||||
{
|
||||
ConsoleColor previousColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.WriteLine(s);
|
||||
Console.ForegroundColor = previousColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue