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 LuaHookBackend HookBackend = new LuaHookBackend();
public LuaHooks HookCalls = new LuaHooks(); public LuaHooks HookCalls = new LuaHooks();
public Dictionary<string, KeyValuePair<string, LuaFunction>> Hooks = new Dictionary public Dictionary<string, KeyValuePair<string, LuaFunction>> Hooks = new Dictionary
<string, KeyValuePair<string, LuaFunction>>(); <string, KeyValuePair<string, LuaFunction>>();
public LuaLoader(string path) public LuaLoader(string path)
{ {
_lua = new Lua(); _lua = new Lua();
@ -89,11 +89,33 @@ namespace TShockAPI.LuaSystem
public void RegisterLuaFunctions() public void RegisterLuaFunctions()
{ {
LuaFunctions LuaFuncs = new LuaFunctions(this); //I just added all the managers for Plugin Development. :)
_lua.RegisterFunction("Print", LuaFuncs, LuaFuncs.GetType().GetMethod("Print")); //Feel free to remove any if you dont feel they are necessay
_lua.RegisterFunction("HookAdd", LuaFuncs, LuaFuncs.GetType().GetMethod("HookAdd")); _lua["Players"] = TShock.Players;
_lua.RegisterFunction("HookRemove", LuaFuncs, LuaFuncs.GetType().GetMethod("HookRemove")); _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.Security.Cryptography;
using System.Text; using System.Text;
using Terraria; using Terraria;
using TShockAPI.LuaSystem;
namespace TShockAPI namespace TShockAPI
{ {
public class Utils 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(); public Random Random = new Random();
//private static List<Group> groups = new List<Group>(); //private static List<Group> groups = new List<Group>();