示例#1
0
            } // ctor

            public override DynamicMetaObject FallbackGetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion)
            {
                // Defer the parameters
                if (!target.HasValue || indexes.Any(c => !c.HasValue))
                {
                    return(Defer(target, indexes));
                }

                Expression expr;

                if (target.Value == null)
                {
                    if (errorSuggestion != null)
                    {
                        return(errorSuggestion);
                    }
                    expr = ThrowExpression(Properties.Resources.rsNullReference, ReturnType);
                }
                else
                {
                    try
                    {
                        expr = Lua.EnsureType(LuaEmit.GetIndex(lua, target, indexes, mo => mo.Expression, mo => mo.LimitType, false), ReturnType);
                    }
                    catch (LuaEmitException e)
                    {
                        if (errorSuggestion != null)
                        {
                            return(errorSuggestion);
                        }
                        expr = ThrowExpression(e.Message, ReturnType);
                    }
                }

                return(new DynamicMetaObject(expr, GetMethodSignatureRestriction(target, indexes)));
            } // func FallbackGetIndex
示例#2
0
        }         // func MemberSetExpression

        private static Expression IndexGetExpression(Scope scope, Token tStart, Expression instance, Expression[] indexes)
        {
            if (instance.Type == typeof(LuaTable))
            {
                if (indexes.Length == 1)
                {
                    var arg = indexes[0];

                    if (LuaTable.IsIndexKey(arg.Type))                     // integer access
                    {
                        return(MemberGetSandbox(
                                   scope,
                                   Expression.Call(instance, Lua.TableGetValueKeyIntMethodInfo,
                                                   ConvertExpression(scope.Runtime, tStart, arg, typeof(int)),
                                                   Expression.Constant(false)
                                                   ),
                                   instance, null
                                   ));
                    }
                    else if (arg.Type == typeof(string))                     // member access
                    {
                        return(MemberGetSandbox(
                                   scope,
                                   Expression.Call(instance, Lua.TableGetValueKeyStringMethodInfo,
                                                   arg,
                                                   Expression.Constant(false),
                                                   Expression.Constant(false)
                                                   ),
                                   instance, null
                                   ));
                    }
                    else                     // key access
                    {
                        return(MemberGetSandbox(
                                   scope,
                                   Expression.Call(instance, Lua.TableGetValueKeyObjectMethodInfo,
                                                   ConvertObjectExpression(scope.Runtime, tStart, arg, true),
                                                   Expression.Constant(false)
                                                   ),
                                   instance, null
                                   ));
                    }
                }
                else
                {
                    return(MemberGetSandbox(
                               scope,
                               Expression.Call(instance, Lua.TableGetValueKeyListMethodInfo,
                                               Expression.NewArrayInit(typeof(object), from i in indexes select ConvertObjectExpression(scope.Runtime, tStart, i, true)),
                                               Expression.Constant(false)
                                               ),
                               instance, null
                               ));
                }
            }
            else if (instance.Type == typeof(LuaResult) && indexes.Length == 1)
            {
                return(MemberGetSandbox(
                           scope,
                           Expression.MakeIndex(
                               instance,
                               Lua.ResultIndexPropertyInfo,
                               new Expression[] { ConvertExpression(scope.Runtime, tStart, indexes[0], typeof(int)) }
                               ),
                           instance, null
                           ));
            }
            else
            {
                return(MemberGetSandbox(scope, SafeExpression(() => LuaEmit.GetIndex(scope.Runtime, instance, indexes, getExpressionFunction, getExpressionTypeFunction, true), tStart), instance, null));
            }
        }         // func IndexGetExpression