예제 #1
0
        public override bool TryConvert(ConvertBinder binder, out object result)
        {
            result = null;
            if (binder.Type == typeof(object[]))
            {
                result = _array;
                return(true);
            }

            if (_array.Length != 1)
            {
                return(false);
            }

            if (_array[0].GetType() == typeof(LuaTable) || _array[0].GetType() == typeof(LuaFunction))
            {
                result = LuaHelper.UnWrapObject(_array[0], _state);
                return(true);
            }

            if (_array[0].GetType() != binder.Type)
            {
                return(false);
            }

            result = Convert.ChangeType(_array[0], binder.Type);

            return(true);
        }
예제 #2
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;

            if (!int.TryParse(binder.Name, out var index))
            {
                return(false);
            }

            if (index >= _array.Length)
            {
                return(false);
            }

            result = LuaHelper.UnWrapObject(_array[index], _state);
            return(true);
        }
예제 #3
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            result = null;

            if (!int.TryParse(indexes[0].ToString(), out var index))
            {
                return(false);
            }

            if (index >= _array.Length)
            {
                return(false);
            }

            result = LuaHelper.UnWrapObject(_array[index], _state);
            return(true);
        }
예제 #4
0
        private object GetTableValue(string name)
        {
            var val = _table[name];

            if (val != null)
            {
                return(LuaHelper.UnWrapObject(val, _state, _path + "." + name));
            }

            //not found, check __index of metatable

            var func = GetMetaFunction("index");

            if (func != null) //metatable and metamethod set
            {
                return(LuaHelper.UnWrapObject(func.Call(_table, name)[0], _state, _path + "." + name));
            }

            return(null);
        }
예제 #5
0
 private object GetLuaValue(string name)
 {
     return(LuaHelper.UnWrapObject(Lua[name], Lua, name));
 }
예제 #6
0
 public dynamic GetMetatable()
 {
     return(LuaHelper.UnWrapObject(
                _state.DoString($"return getmetatable({_path})", "DynamicLua internal operation")[0], _state));
 }