本文整理匯總了C#中NLua.Lua.IsNull方法的典型用法代碼示例。如果您正苦於以下問題:C# Lua.IsNull方法的具體用法?C# Lua.IsNull怎麽用?C# Lua.IsNull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類NLua.Lua
的用法示例。
在下文中一共展示了Lua.IsNull方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: RegisterLuaFunctions
/// <summary>
/// Registers Lua functions found in the specified target.
/// </summary>
/// <param name="luaFunctions">Global lua function table.</param>
/// <param name="target">Object (class,struct) to search in.</param>
/// <param name="vm">The Lua virtual machine.</param>
public static void RegisterLuaFunctions(Lua vm, ref Dictionary<string, LuaFunctionDescriptor> luaFunctions, object target)
{
if(vm.IsNull() || luaFunctions.IsNull())
return;
var type = target.GetType();
foreach(var method in type.GetMethods())
{
foreach(var attribute in Attribute.GetCustomAttributes(method))
{
var attr = attribute as LuaFunctionAttribute;
if(attr.IsNull())
continue;
var parameters = new List<string>();
var paramInfo = method.GetParameters();
if(!attr.FunctionParameters.IsNull() && paramInfo.Length != attr.FunctionParameters.Length)
{
Log.Error("LuaHelper", sLConsole.GetString("Function {0} (exported as {1}): argument number mismatch. Declared {2}, but requires {3}!"), method.Name, attr.FunctionName,
attr.FunctionParameters.Length, paramInfo.Length);
break;
}
// build parameter doc hashtable.
if(!attr.FunctionParameters.IsNull())
parameters.AddRange(paramInfo.Select((t, i) => string.Format("{0} - {1}", t.Name, attr.FunctionParameters[i])));
var descriptor = new LuaFunctionDescriptor(attr.FunctionName, attr.FunctionDocumentation, parameters);
luaFunctions.Add(attr.FunctionName, descriptor);
vm.RegisterFunction(attr.FunctionName, target, method);
}
}
}