本文整理匯總了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();
}
}