mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-16 00:11:28 +00:00
Utilities and an initial webpack loader
This commit is contained in:
21
lib/utils/index.js
Normal file
21
lib/utils/index.js
Normal file
@ -0,0 +1,21 @@
|
||||
module.exports = function(module) {
|
||||
return {
|
||||
getI32: function(ptr) {
|
||||
return new Int32Array(module.memory.buffer, ptr, 4)[0];
|
||||
},
|
||||
getU32: function(ptr) {
|
||||
return new Uint32Array(module.memory.buffer, ptr, 4)[0];
|
||||
},
|
||||
getF32: function(ptr) {
|
||||
return new Float32Array(module.memory.buffer, ptr, 4)[0];
|
||||
},
|
||||
getF64: function(ptr) {
|
||||
return new Float64Array(module.memory.buffer, ptr, 8)[0];
|
||||
},
|
||||
getString: function(ptr) {
|
||||
var len = new Uint32Array(module.memory.buffer, ptr, 4)[0];
|
||||
var str = new Uint16Array(module.memory.buffer, ptr + 4, len << 1);
|
||||
return String.fromCharCode.apply(String, str);
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user