Exemple #1
0
 public ByteBuffer(int initialCapacity, int maxCapacity, ByteBufferAllocator allocator)
 {
     _data          = new byte[initialCapacity];
     _maxCapacity   = maxCapacity > initialCapacity ? maxCapacity : initialCapacity;
     _writePosition = 0;
     _readPosition  = 0;
     _allocator     = allocator;
 }
        public DuktapeVM(IO.ByteBufferAllocator allocator = null)
        {
            _instance            = this;
            _byteBufferAllocator = allocator;

            var ctx = DuktapeDLL.duk_create_heap_default();

            _ctx = new DuktapeContext(this, ctx);
            DuktapeAux.duk_open(ctx);
            DuktapeVM.duk_open_module(ctx);
            DuktapeDLL.duk_unity_open(ctx);
        }
Exemple #3
0
        // poolSize: 预分配内存
        public DuktapeVM(IO.ByteBufferAllocator allocator = null, int poolSize = 0)
        {
            _instance            = this;
            _byteBufferAllocator = allocator;
            _memAllocPoolSize    = poolSize >= 0 ? (uint)poolSize : 0;
            _memAllocPool        = _memAllocPoolSize != 0 ? Marshal.AllocHGlobal(poolSize) : IntPtr.Zero;
            var ctx = DuktapeDLL.duk_unity_create_heap(_memAllocPool, _memAllocPoolSize);

            _ctx = new DuktapeContext(this, ctx);
            DuktapeDLL.duk_unity_open(ctx);
            DuktapeAux.duk_open(ctx);
            DuktapeVM.duk_open_module(ctx);
        }
Exemple #4
0
        public void Initialize(IO.ByteBufferAllocator byteBufferAllocator, IFileResolver fileResolver, IDuktapeListener listener, int step = 30)
        {
            _byteBufferAllocator = byteBufferAllocator;
            _fileResolver        = fileResolver;
            var runner = DuktapeRunner.GetRunner();

            if (runner != null)
            {
                runner.StartCoroutine(_InitializeStep(listener, step));
            }
            else
            {
                var e = _InitializeStep(listener, step);
                while (e.MoveNext())
                {
                    ;
                }
            }
        }