Пример #1
0
        public ILuaTable CreateContext(ILuaTable scope)
        {
            var env = _env;
            var tbl = env.NewTable();

            ILuaTable meta = NewTable();

            meta.Set("__index", scope != null ? (scope as XLuaTable).SourceTable : env.Environment.Global);
            tbl.SetMetaTable(meta);
            meta.Dispose();

            return(tbl);
        }
Пример #2
0
        public void Execute(List <Entity <IUIPool> > entities)
        {
            foreach (var scopeEntity in entities)
            {
                ILuaTable props   = null;
                ILuaTable state   = _lua.NewTable();
                ILuaTable context = _lua.CreateContext();

                if (scopeEntity.Has <Parent>())
                {
                    // Child scope (embeded) - requesting props is required!
                    var parent = _uiPool.GetParent(scopeEntity);
                    props = parent.Has <LuaScopeProps>()
                        ? parent.GetAttribute <LuaScopeProps, ILuaTable>()
                        : _lua.NewTable();
                }
                else if (scopeEntity.Has <LuaScopeProps>())
                {
                    props = scopeEntity.GetAttribute <LuaScopeProps, ILuaTable>();
                }
                else
                {
                    // Root scope must create clean props table
                    props = _lua.NewTable();
                }

                props.Set("Test", (Action)(() => Debug.Log("test")));

                context.Set("state", state);
                context.Set("props", props);
                context.Set("scope", new ScopeTable(scopeEntity, _uiPool));

                scopeEntity.SetAttribute <LuaScopeProps, ILuaTable>(props);
                scopeEntity.SetAttribute <LuaScopeState, ILuaTable>(state);
                scopeEntity.SetAttribute <LuaScopeContext, ILuaTable>(context);
            }
        }