Added Some Functions. _lua looks good!

This commit is contained in:
Steven French 2012-01-05 01:49:49 +13:00
parent 332fce2eb7
commit a1d4328ec4
2 changed files with 38 additions and 5 deletions

View file

@ -17,7 +17,7 @@ namespace TShockAPI.LuaSystem
public LuaHookBackend HookBackend = new LuaHookBackend();
public LuaHooks HookCalls = new LuaHooks();
public Dictionary<string, KeyValuePair<string, LuaFunction>> Hooks = new Dictionary
<string, KeyValuePair<string, LuaFunction>>();
<string, KeyValuePair<string, LuaFunction>>();
public LuaLoader(string path)
{
_lua = new Lua();
@ -89,11 +89,33 @@ namespace TShockAPI.LuaSystem
public void RegisterLuaFunctions()
{
LuaFunctions LuaFuncs = new LuaFunctions(this);
_lua.RegisterFunction("Print", LuaFuncs, LuaFuncs.GetType().GetMethod("Print"));
_lua.RegisterFunction("HookAdd", LuaFuncs, LuaFuncs.GetType().GetMethod("HookAdd"));
_lua.RegisterFunction("HookRemove", LuaFuncs, LuaFuncs.GetType().GetMethod("HookRemove"));
//I just added all the managers for Plugin Development. :)
//Feel free to remove any if you dont feel they are necessay
_lua["Players"] = TShock.Players;
_lua["Bans"] = TShock.Bans;
_lua["Warps"] = TShock.Warps;
_lua["Regions"] = TShock.Regions;
_lua["Backups"] = TShock.Backups;
_lua["Groups"] = TShock.Groups;
_lua["Users"] = TShock.Users;
_lua["Itembans"] = TShock.Users;
LuaFunctions LuaFuncs = new LuaFunctions(this);
var LuaFuncMethods = LuaFuncs.GetType().GetMethods();
foreach (System.Reflection.MethodInfo method in LuaFuncMethods)
{
_lua.RegisterFunction(method.Name, LuaFuncs, method);
}
//Utils
Utils LuaUtils = new Utils(this);
var LuaUtilMethods = LuaUtils.GetType().GetMethods();
foreach (System.Reflection.MethodInfo method in LuaUtilMethods)
{
_lua.RegisterFunction(method.Name, LuaUtils, method);
}
}
}

View file

@ -24,11 +24,22 @@ using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using Terraria;
using TShockAPI.LuaSystem;
namespace TShockAPI
{
public class Utils
{
LuaLoader Parent; //For Lua Functions that require the LuaLoader
public Utils()
{
}
public Utils(LuaLoader parent)
{
Parent = parent;
}
public Random Random = new Random();
//private static List<Group> groups = new List<Group>();