Exemplo n.º 1
0
        public void Start()
        {
            if (ReadBytes == null)
            {
                ReadBytes = System.IO.File.ReadAllBytes;
            }

            L         = Lua.newstate();
            mainState = L;

            luaL_openlibs(L);
            lua_atpanic(L, PanicCallback);

            Register("print", DoPrint);
            Register("dofile", DoFile);
            Register("loadfile", LoadFile);

            errorFuncRef = get_error_func_ref(L);

            AddAssembly(Assembly.GetExecutingAssembly());

            _global = LuaRef.Globals(L);
            _global.Set("luna", LuaRef.CreateTable(L));

            Register("luna.typeof", GetClassType);
            Register("luna.findType", FindClassType);

#if LUNA_SCRIPT
            DoString(coroutineSource);
            DoString(classSource);
            DoString(listSource);
#endif

            _binder = new SharpModule(this);

            AddSearcher(LuaLoader);

            LunaNative.Init(L);
            SharpObject.Init(L);

            RegisterWraps(this.GetType());

            foreach (var moduleInfo in this._config)
            {
                this.RegisterModel(moduleInfo);
            }

            PostInit?.Invoke();

            var it = _classWrapers.GetEnumerator();
            while (it.MoveNext())
            {
                if (!SharpModule.IsRegistered(it.Current.Key))
                {
                    RegisterClass(it.Current.Key);
                }
            }

            //_classWrapers.Clear();
        }
Exemplo n.º 2
0
        public SharpClass RegisterModel(ModuleInfo moduleInfo)
        {
            var model = string.IsNullOrEmpty(moduleInfo.Name) ? _binder : SharpModule.Get(_binder, moduleInfo.Name);

            foreach (var t in moduleInfo)
            {
                model.RegClass(t.type);
            }
            return(model);
        }
Exemplo n.º 3
0
        public SharpClass RegisterModel(string name, IEnumerable <Type> types)
        {
            var model = string.IsNullOrEmpty(name) ? _binder : SharpModule.Get(_binder, name);

            foreach (Type t in types)
            {
                model.RegClass(t);
            }
            return(model);
        }
Exemplo n.º 4
0
        public SharpModule(SharpModule parent, string name) : base(parent)
        {
            LuaRef parentMeta = parent.meta;
            LuaRef luaref     = parentMeta.RawGet(name) as LuaRef;

            if (luaref)
            {
                meta = luaref;
                return;
            }

            this.parent = parent;
            meta        = LunaNative.create_module(parentMeta.State, parentMeta, name);
            Name        = name;
        }
Exemplo n.º 5
0
        public SharpModule GetModule(string name)
        {
            if (registeredModule == null)
            {
                registeredModule = new Dictionary <string, SharpModule>();
            }

            if (registeredModule.TryGetValue(name, out var module))
            {
                return(module);
            }

            module = new SharpModule(this, name);
            registeredModule.Add(name, module);
            return(module);
        }
Exemplo n.º 6
0
        public static SharpModule Get(SharpModule global, string name)
        {
            if (registeredModule == null)
            {
                registeredModule = new Dictionary <string, SharpModule>();
            }

            if (registeredModule.TryGetValue(name, out var module))
            {
                return(module);
            }

            LuaRef meta = new LuaRef(global.State, name);

            module = new SharpModule(global, name, meta);
            registeredModule.Add(name, module);
            return(module);
        }
Exemplo n.º 7
0
        public SharpClass GetClass(Type classType, Type superClass = null)
        {
            if (registeredClass.TryGetValue(classType, out var bindClass))
            {
                return(bindClass);
            }

            if (classType == superClass)
            {
                return(CreateClass(classType, null, this));
            }

            var parentType = classType.BaseType;

            while (superClass == null)
            {
                if (parentType == null)
                {
                    break;
                }

                if (SharpModule.IsRegistered(parentType))
                {
                    superClass = parentType;
                    break;
                }

                if (parentType == typeof(object))
                {
                    break;
                }

                parentType = parentType.BaseType;
            }

            return(CreateClass(classType, superClass, this));
        }
Exemplo n.º 8
0
 public SharpModule(SharpModule parent, string name, LuaRef meta) : base(parent)
 {
     this.meta   = meta;
     this.parent = parent;
     Name        = name;
 }