Esempio 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();
        }
Esempio n. 2
0
        public static LuaRef create_module(lua_State L, LuaRef parentModule, string name)
        {
            int moduleRef = parentModule.Ref;

#if C_API
            int metaRef;
            metaRef = luna_create_module(L, moduleRef, name);
            return(new LuaRef(metaRef, L));
#else
            string fullName = GetFullName(parentModule, name);

            LuaRef meta = LuaRef.CreateTable(L);
            meta.SetMetaTable(meta);

            meta.RawSet("__index", (LuaNativeFunction)module_index);
            meta.RawSet("__newindex", (LuaNativeFunction)module_newindex);
            meta.RawSet(___getters, LuaRef.CreateTable(L));
            meta.RawSet(___setters, LuaRef.CreateTable(L));
            meta.RawSet(___type, fullName);
            parentModule.RawSet(name, meta);
            return(meta);
#endif
        }
Esempio n. 3
0
        public static LuaRef create_class(lua_State L, LuaRef parentModule, string name, Type classType, LuaNativeFunction dctor)
        {
            int moduleRef = parentModule.Ref;
            int classId   = SharpObject.TypeID(classType);

#if C_API
            int metaRef = luna_create_class(L, moduleRef, name, classId, dctor.ToFunctionPointer());
            var meta    = new LuaRef(metaRef, L);
#else
            string fullName = GetFullName(parentModule, name);

            LuaRef meta = LuaRef.CreateTable(L);
            meta.SetMetaTable(meta);

            meta.RawSet("__index", (LuaNativeFunction)class_index);
            meta.RawSet("__newindex", (LuaNativeFunction)class_newindex);
            meta.RawSet(___getters, LuaRef.CreateTable(L));
            meta.RawSet(___setters, LuaRef.CreateTable(L));
            meta.RawSet(___type, fullName);

            if (dctor != null)
            {
                meta.RawSet("__gc", dctor);
            }

            if (classId != 0)
            {
                LuaRef registry = LuaRef.Registry(L);
                registry.RawSet(classId, meta);
            }

            parentModule.RawSet(name, meta);
#endif
            meta.RawSet("type", classType);
            return(meta);
        }