本文整理汇总了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);
}
}
}