Introduce LuaScriptContext function cache
This commit is contained in:
@@ -13,17 +13,20 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using NLua;
|
using NLua;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Scripting
|
namespace OpenRA.Mods.RA.Scripting
|
||||||
{
|
{
|
||||||
public class LuaScriptContext : IDisposable
|
public class LuaScriptContext : IDisposable
|
||||||
{
|
{
|
||||||
public Lua Lua { get; private set; }
|
public Lua Lua { get; private set; }
|
||||||
|
readonly Cache<string, LuaFunction> functionCache;
|
||||||
|
|
||||||
public LuaScriptContext()
|
public LuaScriptContext()
|
||||||
{
|
{
|
||||||
Log.Write("debug", "Creating Lua script context");
|
Log.Write("debug", "Creating Lua script context");
|
||||||
Lua = new Lua();
|
Lua = new Lua();
|
||||||
|
functionCache = new Cache<string, LuaFunction>(Lua.GetFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterObject(object target, string tableName, bool exposeAllMethods)
|
public void RegisterObject(object target, string tableName, bool exposeAllMethods)
|
||||||
@@ -104,7 +107,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var function = Lua.GetFunction(name);
|
var function = functionCache[name];
|
||||||
if (function == null)
|
if (function == null)
|
||||||
return null;
|
return null;
|
||||||
return function.Call(args);
|
return function.Call(args);
|
||||||
|
|||||||
Reference in New Issue
Block a user