Beispiel #1
0
        public static Value lib_random_random_int(VmContext vm, Value[] args)
        {
            if (((args[0].type != 3) || (args[1].type != 3)))
            {
                return(vm.globalNull);
            }
            int lower = (int)args[0].internalValue;
            int upper = (int)args[1].internalValue;

            if ((lower >= upper))
            {
                return(vm.globalNull);
            }
            int value = (int)((PST_Random.NextDouble() * (upper - lower)));

            return(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, (lower + value)));
        }
Beispiel #2
0
        public static Value lib_game_audio_sfx_stop(VmContext vm, Value[] args)
        {
            ObjectInstance channel                    = (ObjectInstance)args[0].internalValue;
            object         nativeChannel              = channel.nativeData[0];
            ObjectInstance resource                   = (ObjectInstance)args[1].internalValue;
            object         nativeResource             = resource.nativeData[0];
            int            resourceId                 = (int)args[2].internalValue;
            int            currentState               = (int)args[3].internalValue;
            bool           completeStopAndFreeChannel = (bool)args[4].internalValue;
            bool           isAlreadyPaused            = ((currentState == 2) && !completeStopAndFreeChannel);

            if (((currentState != 3) && !isAlreadyPaused))
            {
                lib_audio_sfx_stopImpl(nativeChannel, nativeResource, resourceId, (currentState == 1), completeStopAndFreeChannel);
            }
            return(vm.globals.valueNull);
        }
Beispiel #3
0
        public static Value lib_fileiocommon_fileInfo(VmContext vm, Value[] args)
        {
            int mask = (int)args[2].internalValue;

            FileIOCommonHelper.GetFileInfo((string)args[1].internalValue, mask, PST_IntBuffer16, PST_FloatBuffer16);
            ListImpl outputList = (ListImpl)args[3].internalValue;

            Interpreter.Vm.CrayonWrapper.clearList(outputList);
            VmGlobals globals = vm.globals;

            Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildBoolean(globals, (PST_IntBuffer16[0] > 0)));
            Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildBoolean(globals, (PST_IntBuffer16[1] > 0)));
            if (((mask & 1) != 0))
            {
                Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildInteger(globals, PST_IntBuffer16[2]));
            }
            else
            {
                Interpreter.Vm.CrayonWrapper.addToList(outputList, globals.valueNull);
            }
            if (((mask & 2) != 0))
            {
                Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildBoolean(globals, (PST_IntBuffer16[3] > 0)));
            }
            else
            {
                Interpreter.Vm.CrayonWrapper.addToList(outputList, globals.valueNull);
            }
            if (((mask & 4) != 0))
            {
                Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildFloat(globals, PST_FloatBuffer16[0]));
            }
            else
            {
                Interpreter.Vm.CrayonWrapper.addToList(outputList, globals.valueNull);
            }
            if (((mask & 8) != 0))
            {
                Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildFloat(globals, PST_FloatBuffer16[1]));
            }
            else
            {
                Interpreter.Vm.CrayonWrapper.addToList(outputList, globals.valueNull);
            }
            return(args[3]);
        }
Beispiel #4
0
        public static Value lib_imageencoder_encodeToBytes(VmContext vm, Value[] args)
        {
            object       platformBitmap  = Interpreter.Vm.CrayonWrapper.getNativeDataItem(args[0], 0);
            int          imageFormat     = (int)args[1].internalValue;
            List <Value> byteOutputList  = new List <Value>();
            int          statusCode      = ImageEncoderUtil.Encode(platformBitmap, imageFormat, byteOutputList, vm.globals.positiveIntegers);
            int          length          = byteOutputList.Count;
            ListImpl     finalOutputList = (ListImpl)args[2].internalValue;
            int          i = 0;

            while ((i < length))
            {
                Interpreter.Vm.CrayonWrapper.addToList(finalOutputList, byteOutputList[i]);
                i += 1;
            }
            return(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, statusCode));
        }
Beispiel #5
0
        public static Value lib_srandom_getInteger(VmContext vm, Value[] args)
        {
            ListImpl intPtr = (ListImpl)args[0].internalValue;
            int      value1 = 0;

            value1 = ((((int)intPtr.array[0].internalValue * 20077) + 12345) & 65535);
            int value2 = (((value1 * 20077) + 12345) & 65535);
            int value3 = (((value2 * 20077) + 12345) & 65535);
            int value4 = (((value3 * 20077) + 12345) & 65535);

            intPtr.array[0] = Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, value4);
            value1          = ((value1 >> 8) & 255);
            value2          = ((value2 >> 8) & 255);
            value3          = ((value3 >> 8) & 255);
            value4          = ((value4 >> 8) & 127);
            return(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, ((value4 << 24) | (value3 << 16) | (value2 << 8) | value1)));
        }
Beispiel #6
0
        public static Value lib_graphics2dtext_isResourceAvailable(VmContext vm, Value[] args)
        {
            string path = (string)args[0].internalValue;
            Value  res  = Interpreter.Vm.CrayonWrapper.resource_manager_getResourceOfType(vm, path, "TTF");

            if ((res.type == 1))
            {
                return(vm.globalFalse);
            }
            ListImpl resList = (ListImpl)res.internalValue;

            if (!(bool)Interpreter.Vm.CrayonWrapper.getItemFromList(resList, 0).internalValue)
            {
                return(vm.globalFalse);
            }
            return(vm.globalTrue);
        }
Beispiel #7
0
        public static Value lib_cryptosha1_digest(VmContext vm, Value[] args)
        {
            ObjectInstance obj      = (ObjectInstance)args[0].internalValue;
            ListImpl       output   = (ListImpl)args[1].internalValue;
            List <int>     byteList = (List <int>)obj.nativeData[0];

            int[] resultBytes = lib_cryptosha1_digestImpl(byteList);
            int   i           = 0;

            while ((i < 20))
            {
                int b = resultBytes[i];
                Interpreter.Vm.CrayonWrapper.addToList(output, vm.globals.positiveIntegers[b]);
                i += 1;
            }
            return(args[1]);
        }
Beispiel #8
0
        public static Value lib_graphics2d_flip(VmContext vm, Value[] args)
        {
            bool bool1 = false;
            bool bool2 = false;
            int  i     = 0;

            object[]       objArray1    = null;
            object[]       objArray2    = null;
            object         object1      = null;
            ObjectInstance objInstance1 = null;
            ObjectInstance objInstance2 = null;
            Value          arg1         = args[0];
            Value          arg2         = args[1];
            Value          arg3         = args[2];
            Value          arg4         = args[3];
            Value          arg5         = args[4];
            Value          arg6         = args[5];

            objInstance1            = (ObjectInstance)arg1.internalValue;
            objInstance2            = (ObjectInstance)arg2.internalValue;
            objArray1               = objInstance1.nativeData;
            objArray2               = new object[7];
            objInstance2.nativeData = objArray2;
            bool1 = (bool)arg3.internalValue;
            bool2 = (bool)arg4.internalValue;
            i     = 6;
            while ((i >= 0))
            {
                objArray2[i] = objArray1[i];
                i           -= 1;
            }
            if (bool1)
            {
                object1      = objArray1[1];
                objArray2[1] = objArray2[3];
                objArray2[3] = object1;
            }
            if (bool2)
            {
                object1      = objArray1[2];
                objArray2[2] = objArray2[4];
                objArray2[4] = object1;
            }
            return(arg2);
        }
Beispiel #9
0
        public static Value lib_matrices_toVector(VmContext vm, Value[] args)
        {
            ObjectInstance obj = (ObjectInstance)args[0].internalValue;

            object[] nd     = obj.nativeData;
            double[] data   = (double[])nd[0];
            int      width  = (int)nd[1];
            int      height = (int)nd[2];
            int      length = (width * height);

            if ((args[1].type != 6))
            {
                nd[5] = "Output argument must be a list";
                return(vm.globalNull);
            }
            ListImpl output = (ListImpl)args[1].internalValue;

            while ((output.size < length))
            {
                Interpreter.Vm.CrayonWrapper.addToList(output, vm.globalNull);
            }
            double value  = 0.0;
            Value  toList = null;
            int    i      = 0;

            while ((i < length))
            {
                value = data[i];
                if ((value == 0))
                {
                    toList = vm.globals.floatZero;
                }
                else if ((value == 1))
                {
                    toList = vm.globals.floatOne;
                }
                else
                {
                    toList = new Value(4, data[i]);
                }
                output.array[i] = toList;
                i += 1;
            }
            return(args[1]);
        }
Beispiel #10
0
        public static Value lib_game_getTouchState(VmContext vm, Value[] args)
        {
            ListImpl output = (ListImpl)args[0].internalValue;

            int[] data = new int[31];
            data[0] = 0;
            AlwaysTrue();
            int _len = data[0];
            int end  = ((_len * 3) + 1);
            int i    = 1;

            while ((i < end))
            {
                Interpreter.Vm.CrayonWrapper.addToList(output, Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, data[i]));
                i += 1;
            }
            return(vm.globalNull);
        }
Beispiel #11
0
        public static Value lib_http_getResponseBytes(VmContext vm, Value[] args)
        {
            Value          outputListValue = args[1];
            ObjectInstance objInstance1    = (ObjectInstance)args[0].internalValue;

            object[]     objArray1 = objInstance1.nativeData;
            List <Value> tList     = new List <Value>();

            HttpHelper.GetResponseBytes(objArray1[0], vm.globals.positiveIntegers, tList);
            ListImpl outputList = (ListImpl)outputListValue.internalValue;
            Value    t          = Interpreter.Vm.CrayonWrapper.buildList(tList);
            ListImpl otherList  = (ListImpl)t.internalValue;

            outputList.capacity = otherList.capacity;
            outputList.array    = otherList.array;
            outputList.size     = tList.Count;
            return(outputListValue);
        }
Beispiel #12
0
        public static Value lib_matrices_setValue(VmContext vm, Value[] args)
        {
            ObjectInstance obj = (ObjectInstance)args[0].internalValue;

            object[] nd = obj.nativeData;
            if (((args[1].type != 3) || (args[2].type != 3)))
            {
                nd[5] = "Invalid coordinates";
                return(vm.globalNull);
            }
            int x      = (int)args[1].internalValue;
            int y      = (int)args[2].internalValue;
            int width  = (int)nd[1];
            int height = (int)nd[2];

            if (((x < 0) || (x >= width) || (y < 0) || (y >= height)))
            {
                nd[5] = "Coordinates out of range.";
                return(vm.globalNull);
            }
            double value = 0.0;

            if ((args[3].type == 4))
            {
                value = (double)args[3].internalValue;
            }
            else if ((args[3].type == 3))
            {
                value = (0.0 + (int)args[3].internalValue);
            }
            else
            {
                nd[5] = "Value must be a number.";
                return(vm.globalNull);
            }
            int index = ((y * width) + x);

            double[] data       = (double[])nd[0];
            Value[]  valueArray = (Value[])nd[3];
            data[index]       = value;
            valueArray[index] = Interpreter.Vm.CrayonWrapper.buildFloat(vm.globals, value);
            return(args[0]);
        }
    // Delete all maps associated with the deleted view
    private async Task DeleteClonedMaps(Guid viewId, VmContext dbContext)
    {
        var toDelete = await dbContext.Maps
                       .Where(m => m.ViewId == viewId)
                       .Include(m => m.Coordinates)
                       .ToListAsync();

        foreach (var map in toDelete)
        {
            foreach (var coord in map.Coordinates)
            {
                dbContext.Remove(coord);
            }

            dbContext.Remove(map);
        }

        await dbContext.SaveChangesAsync();
    }
Beispiel #14
0
        public static Value lib_graphics2dtext_glSetNativeDataIntArray(VmContext vm, Value[] args)
        {
            ObjectInstance obj = (ObjectInstance)args[0].internalValue;

            object[] nativeData = obj.nativeData;
            ListImpl values     = (ListImpl)args[2].internalValue;
            int      length     = values.size;

            int[] intArray = new int[length];
            int   i        = 0;

            while ((i < length))
            {
                intArray[i] = (int)Interpreter.Vm.CrayonWrapper.getItemFromList(values, i).internalValue;
                i          += 1;
            }
            nativeData[(int)args[1].internalValue] = intArray;
            return(vm.globalNull);
        }
Beispiel #15
0
        public static Value lib_fileiocommon_directoryList(VmContext vm, Value[] args)
        {
            Value         diskhost    = args[0];
            string        path        = (string)args[1].internalValue;
            bool          useFullPath = (bool)args[2].internalValue;
            ListImpl      outputList  = (ListImpl)args[3].internalValue;
            List <string> stringList1 = new List <string>();
            int           sc          = FileIOCommonHelper.GetDirectoryList(path, useFullPath, stringList1);

            if ((sc == 0))
            {
                int i = 0;
                while ((i < stringList1.Count))
                {
                    Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildString(vm.globals, stringList1[i]));
                    i += 1;
                }
            }
            return(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, sc));
        }
Beispiel #16
0
        public static Value lib_zip_readerPeekNextEntry(VmContext vm, Value[] args)
        {
            ObjectInstance obj = (ObjectInstance)args[0].internalValue;

            object[] nd     = obj.nativeData;
            ListImpl output = (ListImpl)args[1].internalValue;
            int      execId = (int)args[2].internalValue;

            bool[]     boolOut  = new bool[3];
            string[]   nameOut  = new string[1];
            List <int> integers = new List <int>();

            ZipHelper.ReadNextZipEntry(nd[0], (int)nd[1], boolOut, nameOut, integers);
            if (AlwaysFalse())
            {
                Interpreter.Vm.CrayonWrapper.vm_suspend_context_by_id(vm, execId, 1);
                return(vm.globalTrue);
            }
            return(lib_zip_readerPeekNextEntryCallback(!boolOut[0], boolOut[1], boolOut[2], nameOut[0], integers, nd, output, vm));
        }
Beispiel #17
0
        public static Value lib_easing_apply_pts(VmContext vm, Value[] args)
        {
            ListImpl sampleValues = (ListImpl)args[1].internalValue;
            int      _len         = sampleValues.size;

            double[] samples = new double[_len];
            int      i       = 0;

            while ((i < _len))
            {
                samples[i] = (double)sampleValues.array[i].internalValue;
                i         += 1;
            }
            samples[0]          = 0.0;
            samples[(_len - 1)] = 1.0;
            ObjectInstance o = (ObjectInstance)args[0].internalValue;

            o.nativeObject = new EasingSampling(_len, samples);
            return(vm.globals.valueNull);
        }
Beispiel #18
0
        public static Value lib_imagewebresources_bytesToImage(VmContext vm, Value[] args)
        {
            ObjectInstance objInstance1 = (ObjectInstance)args[0].internalValue;
            object         object1      = objInstance1.nativeData[0];
            ListImpl       list1        = (ListImpl)args[1].internalValue;
            Value          value        = Interpreter.Vm.CrayonWrapper.getItemFromList(list1, 0);

            object[] objArray1 = new object[3];
            objInstance1            = (ObjectInstance)value.internalValue;
            objInstance1.nativeData = objArray1;
            if (ImageDownloader.BytesToImage(object1, objArray1))
            {
                Value width  = Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, (int)objArray1[1]);
                Value height = Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, (int)objArray1[2]);
                list1.array[1] = width;
                list1.array[2] = height;
                return(vm.globalTrue);
            }
            return(vm.globalFalse);
        }
Beispiel #19
0
        public static Value lib_graphics2dtext_glGenerateAndLoadTexture(VmContext vm, Value[] args)
        {
            ListImpl xs        = (ListImpl)args[0].internalValue;
            ListImpl ys        = (ListImpl)args[1].internalValue;
            ListImpl tiles     = (ListImpl)args[2].internalValue;
            int      tileCount = xs.size;

            object[][] tileNativeDatas = new object[tileCount][];
            int[]      coordinates     = new int[(tileCount * 4)];
            object[]   nativeData      = null;
            int        i = 0;

            while ((i < tileCount))
            {
                nativeData                 = ((ObjectInstance)Interpreter.Vm.CrayonWrapper.getItemFromList(tiles, i).internalValue).nativeData;
                tileNativeDatas[i]         = nativeData;
                coordinates[(i * 4)]       = (int)Interpreter.Vm.CrayonWrapper.getItemFromList(xs, i).internalValue;
                coordinates[((i * 4) + 1)] = (int)Interpreter.Vm.CrayonWrapper.getItemFromList(ys, i).internalValue;
                coordinates[((i * 4) + 2)] = (int)nativeData[1];
                coordinates[((i * 4) + 3)] = (int)nativeData[2];
                i += 1;
            }
            int height    = ((int)args[3].internalValue - 1);
            int bitWalker = height;

            while ((bitWalker > 0))
            {
                bitWalker = (bitWalker >> 1);
                height    = (height | bitWalker);
            }
            height += 1;
            object textureSheetBitmap = Graphics2DTextHelper.GenerateTextureAndAllocateFloatInfo(tileNativeDatas, coordinates, 1024, height);

            i = 0;
            while ((i < tileCount))
            {
                tileNativeDatas[i][6] = textureSheetBitmap;
                i += 1;
            }
            return(vm.globalNull);
        }
Beispiel #20
0
        public static Value lib_textencoding_convertBytesToText(VmContext vm, Value[] args)
        {
            if ((args[0].type != 6))
            {
                return(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, 2));
            }
            ListImpl byteList = (ListImpl)args[0].internalValue;
            int      format   = (int)args[1].internalValue;
            ListImpl output   = (ListImpl)args[2].internalValue;

            string[] strOut = PST_StringBuffer16;
            int      length = byteList.size;

            int[] unwrappedBytes = new int[length];
            int   i     = 0;
            Value value = null;
            int   c     = 0;

            while ((i < length))
            {
                value = byteList.array[i];
                if ((value.type != 3))
                {
                    return(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, 3));
                }
                c = (int)value.internalValue;
                if (((c < 0) || (c > 255)))
                {
                    return(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, 3));
                }
                unwrappedBytes[i] = c;
                i += 1;
            }
            int sc = TextEncodingHelper.BytesToText(unwrappedBytes, format, strOut);

            if ((sc == 0))
            {
                Interpreter.Vm.CrayonWrapper.addToList(output, Interpreter.Vm.CrayonWrapper.buildString(vm.globals, strOut[0]));
            }
            return(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, sc));
        }
Beispiel #21
0
        public static void ChunkLoadAsync(VmContext vm, Dictionary <int, object> loadedChunks, int chunkId, int[] chunkIds, Value loadedCallback)
        {
            string path = "ch_" + chunkId + ".png";

            loadedChunks[chunkId] = ((ResourceReader)vm.environment.resourceReader).ReadImageResource(path);
            if (loadedChunks[chunkId] == null)
            {
                throw new Exception("Image resource not available: " + path);
            }
            int total  = chunkIds.Length;
            int loaded = 0;

            foreach (int otherChunk in chunkIds)
            {
                if (loadedChunks.ContainsKey(otherChunk))
                {
                    loaded++;
                }
            }
            TranslationHelper.GetEventLoop(vm).ExecuteFunctionPointerNativeArgs(loadedCallback, new object[] { chunkId, loaded, total });
        }
Beispiel #22
0
 public static Value lib_http_fastEnsureAllBytes(VmContext vm, Value[] args)
 {
     if ((args[0].type == 6))
     {
         ListImpl list1     = (ListImpl)args[0].internalValue;
         int      i         = list1.size;
         int      int1      = 0;
         int[]    intArray1 = new int[i];
         Value    value     = null;
         while ((i > 0))
         {
             i    -= 1;
             value = list1.array[i];
             if ((value.type != 3))
             {
                 return(vm.globalFalse);
             }
             int1 = (int)value.internalValue;
             if ((int1 < 0))
             {
                 if ((int1 < -128))
                 {
                     return(vm.globalFalse);
                 }
                 int1 += 256;
             }
             else if ((int1 >= 256))
             {
                 return(vm.globalFalse);
             }
             intArray1[i] = int1;
         }
         object[] objArray1 = new object[1];
         objArray1[0] = intArray1;
         ObjectInstance objInstance1 = (ObjectInstance)args[1].internalValue;
         objInstance1.nativeData = objArray1;
         return(vm.globalTrue);
     }
     return(vm.globalFalse);
 }
Beispiel #23
0
        public static Value lib_textencoding_convertTextToBytes(VmContext vm, Value[] args)
        {
            string       value      = (string)args[0].internalValue;
            int          format     = (int)args[1].internalValue;
            bool         includeBom = (bool)args[2].internalValue;
            ListImpl     output     = (ListImpl)args[3].internalValue;
            List <Value> byteList   = new List <Value>();

            int[] intOut       = PST_IntBuffer16;
            int   sc           = TextEncodingHelper.TextToBytes(value, includeBom, format, byteList, vm.globals.positiveIntegers, intOut);
            int   swapWordSize = intOut[0];

            if ((swapWordSize != 0))
            {
                int   i      = 0;
                int   j      = 0;
                int   length = byteList.Count;
                Value swap   = null;
                int   half   = (swapWordSize >> 1);
                int   k      = 0;
                while ((i < length))
                {
                    k = (i + swapWordSize - 1);
                    j = 0;
                    while ((j < half))
                    {
                        swap = byteList[(i + j)];
                        byteList[(i + j)] = byteList[(k - j)];
                        byteList[(k - j)] = swap;
                        j += 1;
                    }
                    i += swapWordSize;
                }
            }
            if ((sc == 0))
            {
                Interpreter.Vm.CrayonWrapper.addToList(output, Interpreter.Vm.CrayonWrapper.buildList(byteList));
            }
            return(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, sc));
        }
Beispiel #24
0
        public static Value lib_datetime_parseDate(VmContext vm, Value[] args)
        {
            int    year             = (int)args[0].internalValue;
            int    month            = (int)args[1].internalValue;
            int    day              = (int)args[2].internalValue;
            int    hour             = (int)args[3].internalValue;
            int    minute           = (int)args[4].internalValue;
            int    microseconds     = (int)args[5].internalValue;
            object nullableTimeZone = lib_datetime_getNativeTimezone(args[6]);

            if (((year >= 1970) && (year < 2100) && (month >= 1) && (month <= 12) && (day >= 1) && (day <= 31) && (hour >= 0) && (hour < 24) && (minute >= 0) && (minute < 60) && (microseconds >= 0) && (microseconds < 60000000)))
            {
                int[] intOut = PST_IntBuffer16;
                DateTimeHelper.ParseDate(intOut, nullableTimeZone, year, month, day, hour, minute, microseconds);
                if ((intOut[0] == 1))
                {
                    double unixFloat = (intOut[1] + (intOut[2]) / (1000000.0));
                    return(Interpreter.Vm.CrayonWrapper.buildFloat(vm.globals, unixFloat));
                }
            }
            return(vm.globalNull);
        }
Beispiel #25
0
        public static Value lib_datetime_initTimeZone(VmContext vm, Value[] args)
        {
            ObjectInstance timezone = (ObjectInstance)args[0].internalValue;

            timezone.nativeData = new object[1];
            object nativeTzRef   = null;
            string readableName  = null;
            int    offsetFromUtc = 0;
            int    isDstObserved = 0;
            string fingerprint   = null;

            if ((args[1].type == 1))
            {
                string[] strOut = PST_StringBuffer16;
                int[]    intOut = PST_IntBuffer16;
                nativeTzRef   = DateTimeHelper.GetDataForLocalTimeZone(strOut, intOut);
                readableName  = strOut[0];
                fingerprint   = strOut[1];
                offsetFromUtc = intOut[0];
                isDstObserved = intOut[1];
            }
            else
            {
                return(vm.globalNull);
            }
            timezone.nativeData    = new object[5];
            timezone.nativeData[0] = nativeTzRef;
            timezone.nativeData[1] = readableName;
            timezone.nativeData[2] = offsetFromUtc;
            timezone.nativeData[3] = (isDstObserved == 1);
            timezone.nativeData[4] = fingerprint;
            List <Value> values = new List <Value>();

            values.Add(Interpreter.Vm.CrayonWrapper.buildString(vm.globals, readableName));
            values.Add(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, offsetFromUtc));
            values.Add(Interpreter.Vm.CrayonWrapper.buildBoolean(vm.globals, (isDstObserved == 1)));
            values.Add(Interpreter.Vm.CrayonWrapper.buildString(vm.globals, fingerprint));
            return(Interpreter.Vm.CrayonWrapper.buildList(values));
        }
Beispiel #26
0
        public static Value lib_datetime_unixToStructured(VmContext vm, Value[] args)
        {
            double       unixTime         = (double)args[0].internalValue;
            object       nullableTimeZone = lib_datetime_getNativeTimezone(args[1]);
            List <Value> output           = new List <Value>();

            int[] intOut  = PST_IntBuffer16;
            bool  success = DateTimeHelper.UnixToStructured(intOut, nullableTimeZone, unixTime);

            if (!success)
            {
                return(vm.globalNull);
            }
            int i = 0;

            while ((i < 9))
            {
                output.Add(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, intOut[i]));
                i += 1;
            }
            return(Interpreter.Vm.CrayonWrapper.buildList(output));
        }
Beispiel #27
0
        public static Value lib_http_populateResponse(VmContext vm, Value[] args)
        {
            Value          arg2         = args[1];
            Value          arg3         = args[2];
            Value          arg4         = args[3];
            ObjectInstance objInstance1 = (ObjectInstance)args[0].internalValue;
            object         object1      = objInstance1.nativeData[0];

            object[]      objArray1   = new object[1];
            List <string> stringList1 = new List <string>();

            HttpHelper.ReadResponseData(object1, PST_IntBuffer16, PST_StringBuffer16, objArray1, stringList1);
            objInstance1            = (ObjectInstance)arg2.internalValue;
            objInstance1.nativeData = objArray1;
            ListImpl outputList = (ListImpl)arg3.internalValue;

            Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, PST_IntBuffer16[0]));
            Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildString(vm.globals, PST_StringBuffer16[0]));
            Value value  = vm.globalNull;
            Value value2 = vm.globalTrue;

            if ((PST_IntBuffer16[1] == 0))
            {
                value  = Interpreter.Vm.CrayonWrapper.buildString(vm.globals, PST_StringBuffer16[1]);
                value2 = vm.globalFalse;
            }
            Interpreter.Vm.CrayonWrapper.addToList(outputList, value);
            Interpreter.Vm.CrayonWrapper.addToList(outputList, value2);
            ListImpl list1 = (ListImpl)arg4.internalValue;
            int      i     = 0;

            while ((i < stringList1.Count))
            {
                Interpreter.Vm.CrayonWrapper.addToList(list1, Interpreter.Vm.CrayonWrapper.buildString(vm.globals, stringList1[i]));
                i += 1;
            }
            return(vm.globalNull);
        }
Beispiel #28
0
        public static Value lib_game_startup(VmContext vm, Value[] args)
        {
            Dictionary <string, System.Func <object[], object> > functionLookup = GameWindow.GetCallbackFunctions();

            string[] names = functionLookup.Keys.ToArray();
            int      i     = 0;

            while ((i < names.Length))
            {
                System.Func <object[], object> fn = null;
                string name = names[i];
                if (!functionLookup.TryGetValue(name, out fn))
                {
                    fn = null;
                }
                if ((fn != null))
                {
                    Interpreter.Vm.CrayonWrapper.registerNamedCallback(vm, "Game", name, fn);
                }
                i += 1;
            }
            return(vm.globalNull);
        }
Beispiel #29
0
        public static Value lib_fileiocommon_fileRead(VmContext vm, Value[] args)
        {
            Value        diskHostObject  = args[0];
            string       sandboxedPath   = (string)args[1].internalValue;
            bool         readDataAsBytes = (bool)args[2].internalValue;
            ListImpl     outputList      = (ListImpl)args[3].internalValue;
            List <Value> tList           = new List <Value>();
            int          statusCode      = FileIOCommonHelper.FileRead(sandboxedPath, readDataAsBytes, PST_StringBuffer16, vm.globals.positiveIntegers, tList);

            if (((statusCode == 0) && !readDataAsBytes))
            {
                Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildString(vm.globals, PST_StringBuffer16[0]));
            }
            else
            {
                Value    t         = Interpreter.Vm.CrayonWrapper.buildList(tList);
                ListImpl tListImpl = (ListImpl)t.internalValue;
                outputList.array    = tListImpl.array;
                outputList.capacity = tListImpl.capacity;
                outputList.size     = tList.Count;
            }
            return(Interpreter.Vm.CrayonWrapper.buildInteger(vm.globals, statusCode));
        }
Beispiel #30
0
        private static void EmitToBuffer(VmContext vm, Value cb, List <string> unifiedStream, string streamName, string value)
        {
            string[] lines = value.Split('\n').Select(line => line + "\n").ToArray();
            bool     newFlushTriggerRequired = false;

            lock (unifiedStream)
            {
                newFlushTriggerRequired = unifiedStream.Count == 0;
                foreach (string line in lines)
                {
                    unifiedStream.Add(streamName);
                    unifiedStream.Add(line);
                }
            }

            if (newFlushTriggerRequired)
            {
                Task.Delay(2).ContinueWith(t =>
                {
                    FlushStream(vm, cb, unifiedStream);
                });
            }
        }