本文整理汇总了C#中NLua.Lua.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Lua.Dispose方法的具体用法?C# Lua.Dispose怎么用?C# Lua.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NLua.Lua
的用法示例。
在下文中一共展示了Lua.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadSingleScript
/// <summary>
/// Load a single script from the specified manifest.
/// </summary>
private void LoadSingleScript(string path, ScriptManifest manifest)
{
string scriptFile = Path.Combine(path, manifest.ScriptFile);
NLua.Lua lua = new NLua.Lua();
lua.LoadCLRPackage();
_luaAPI.RegisterFunctions(lua);
bool success = true;
try
{
lua.DoFile(scriptFile);
LuaFunction fnc = lua.GetFunction("on_load");
if (fnc != null)
{
object[] res = fnc.Call();
if (res != null && res.Length == 1)
{
success = Convert.ToBoolean(res[0]);
}
}
// Cache this script object for event callbacks if the
// init function returns success.
if (success)
{
if (_scriptObjects.ContainsKey(scriptFile))
{
// BUGBUG: What if we have scripts that register events? We need to tell
// them to unregister first. Add an interface for this.
NLua.Lua oldScript = _scriptObjects[scriptFile];
oldScript.Dispose();
_scriptObjects.Remove(scriptFile);
}
_scriptObjects.Add(scriptFile, lua);
}
if (manifest.InstallToToolbar)
{
ToolbarDataItem item = new ToolbarDataItem
{
type = "button",
name = "Script",
label = manifest.Name,
tooltip = manifest.Description,
data = scriptFile,
image = manifest.IconFile
};
CRToolbarItemCollection.DefaultCollection.Add(item);
}
}
catch (Exception e)
{
LogFile.WriteLine("Error loading script {0} : {1}", scriptFile, e.Message);
success = false;
}
if (success)
{
LogFile.WriteLine("Loaded and initialised script {0}", scriptFile);
}
else
{
lua.Dispose();
}
}