Example #1
0
 public void LuaRegister(Type callingLibrary, LuaDocumentation docs = null)
 {
     Lua.NewTable(Name);
     foreach (var method in GetType().GetMethods())
     {
         var foundAttrs = method.GetCustomAttributes(typeof(LuaMethodAttribute), false);
         if (foundAttrs.Length == 0)
         {
             continue;
         }
         Lua.RegisterFunction($"{Name}.{((LuaMethodAttribute) foundAttrs[0]).Name}", this, method);
         docs?.Add(new LibraryFunction(Name, callingLibrary.Description(), method));
     }
 }
Example #2
0
        public void LuaRegister(Type callingLibrary, LuaDocumentation docs = null)
        {
            Lua.NewTable(Name);

            var luaAttr = typeof(LuaMethodAttribute);

            var methods = GetType()
                          .GetMethods()
                          .Where(m => m.GetCustomAttributes(luaAttr, false).Any());

            foreach (var method in methods)
            {
                var luaMethodAttr = (LuaMethodAttribute)method.GetCustomAttributes(luaAttr, false).First();
                var luaName       = Name + "." + luaMethodAttr.Name;
                Lua.RegisterFunction(luaName, this, method);

                docs?.Add(new LibraryFunction(Name, callingLibrary.Description(), method));
            }
        }