示例#1
0
        public Closure(CSFunction csFunction, int nUpvals)
        {
            CSFunction = csFunction;

            if (nUpvals > 0)
            {
                Upvals = new Upvalue[nUpvals];
            }
        }
示例#2
0
        public async Task TestS3EventLambdaFunction()
        {
            IAmazonS3 s3Client = new AmazonS3Client(RegionEndpoint.USWest2);

            var bucketName = "lambda-AWSLambda2-".ToLower() + DateTime.Now.Ticks;
            var key        = "text.txt";

            // Create a bucket an object to setup a test data.
            await s3Client.PutBucketAsync(bucketName);

            try
            {
                await s3Client.PutObjectAsync(new PutObjectRequest
                {
                    BucketName  = bucketName,
                    Key         = key,
                    ContentBody = "sample data"
                });

                // Setup the S3 event object that S3 notifications would create with the fields used by the Lambda function.
                var s3Event = new S3Event
                {
                    Records = new List <S3EventNotification.S3EventNotificationRecord>
                    {
                        new S3EventNotification.S3EventNotificationRecord
                        {
                            S3 = new S3EventNotification.S3Entity
                            {
                                Bucket = new S3EventNotification.S3BucketEntity {
                                    Name = bucketName
                                },
                                Object = new S3EventNotification.S3ObjectEntity {
                                    Key = key
                                }
                            }
                        }
                    }
                };

                // Invoke the lambda function and confirm the content type was returned.
                var function    = new CSFunction(s3Client);
                var contentType = await function.FunctionHandler(s3Event, null);

                Assert.Equal("text/plain", contentType);
            }
            finally
            {
                // Clean up the test data
                await AmazonS3Util.DeleteS3BucketWithObjectsAsync(s3Client, bucketName);
            }
        }
示例#3
0
        public void PushCSClosure(CSFunction f, int n)
        {
            var closure = new Closure(f, n);

            for (var i = n; i > 0; i--)
            {
                var val = _stack.Pop();
                closure.Upvals[i - 1] = new Upvalue {
                    Val = val
                };
            }

            _stack.Push(closure);
        }
示例#4
0
 public void Register(string name, CSFunction f)
 {
     PushCSFunction(f);
     SetGlobal(name);
 }
示例#5
0
 public void PushCSFunction(CSFunction f)
 {
     _stack.Push(new Closure(f, 0));
 }