Quellcode durchsuchen

Blob:getI8/U8/I16/U16/I32/U32/F32/F64;

bjorn vor 2 Jahren
Ursprung
Commit
33e1edf715

+ 37 - 0
api/lovr/data/Blob/getF32.lua

@@ -0,0 +1,37 @@
+return {
+  summary = 'Unpack 32-bit floating point numbers from the Blob.',
+  description = 'Returns 32-bit floating point numbers from the data in the Blob.',
+  arguments = {
+    offset = {
+      type = 'number',
+      default = '0',
+      description = 'A non-negative byte offset to read from.'
+    },
+    count = {
+      type = 'number',
+      default = '1',
+      description = 'The number of floats to read.'
+    }
+  },
+  returns = {
+    ['...'] = {
+      type = 'number',
+      description = '`count` 32-bit floats.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'offset', 'count' },
+      returns = { '...' }
+    }
+  },
+  related = {
+    'Blob:getI8',
+    'Blob:getU8',
+    'Blob:getI16',
+    'Blob:getU16',
+    'Blob:getI32',
+    'Blob:getU32',
+    'Blob:getF64'
+  }
+}

+ 37 - 0
api/lovr/data/Blob/getF64.lua

@@ -0,0 +1,37 @@
+return {
+  summary = 'Unpack 64-bit floating point numbers from the Blob.',
+  description = 'Returns 64-bit floating point numbers from the data in the Blob.',
+  arguments = {
+    offset = {
+      type = 'number',
+      default = '0',
+      description = 'A non-negative byte offset to read from.'
+    },
+    count = {
+      type = 'number',
+      default = '1',
+      description = 'The number of doubles to read.'
+    }
+  },
+  returns = {
+    ['...'] = {
+      type = 'number',
+      description = '`count` 64-bit doubles.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'offset', 'count' },
+      returns = { '...' }
+    }
+  },
+  related = {
+    'Blob:getI8',
+    'Blob:getU8',
+    'Blob:getI16',
+    'Blob:getU16',
+    'Blob:getI32',
+    'Blob:getU32',
+    'Blob:getF32'
+  }
+}

+ 37 - 0
api/lovr/data/Blob/getI16.lua

@@ -0,0 +1,37 @@
+return {
+  summary = 'Unpack signed 16-bit integers from the Blob.',
+  description = 'Returns signed 16-bit integers from the data in the Blob.',
+  arguments = {
+    offset = {
+      type = 'number',
+      default = '0',
+      description = 'A non-negative byte offset to read from.'
+    },
+    count = {
+      type = 'number',
+      default = '1',
+      description = 'The number of integers to read.'
+    }
+  },
+  returns = {
+    ['...'] = {
+      type = 'number',
+      description = '`count` signed 16-bit integers, from -32768 to 32767.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'offset', 'count' },
+      returns = { '...' }
+    }
+  },
+  related = {
+    'Blob:getI8',
+    'Blob:getU8',
+    'Blob:getU16',
+    'Blob:getI32',
+    'Blob:getU32',
+    'Blob:getF32',
+    'Blob:getF64'
+  }
+}

+ 37 - 0
api/lovr/data/Blob/getI32.lua

@@ -0,0 +1,37 @@
+return {
+  summary = 'Unpack signed 32-bit integers from the Blob.',
+  description = 'Returns signed 32-bit integers from the data in the Blob.',
+  arguments = {
+    offset = {
+      type = 'number',
+      default = '0',
+      description = 'A non-negative byte offset to read from.'
+    },
+    count = {
+      type = 'number',
+      default = '1',
+      description = 'The number of integers to read.'
+    }
+  },
+  returns = {
+    ['...'] = {
+      type = 'number',
+      description = '`count` signed 32-bit integers, from -2147483648 to 2147483647.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'offset', 'count' },
+      returns = { '...' }
+    }
+  },
+  related = {
+    'Blob:getI8',
+    'Blob:getU8',
+    'Blob:getI16',
+    'Blob:getU16',
+    'Blob:getU32',
+    'Blob:getF32',
+    'Blob:getF64'
+  }
+}

+ 37 - 0
api/lovr/data/Blob/getI8.lua

@@ -0,0 +1,37 @@
+return {
+  summary = 'Unpack signed 8-bit integers from the Blob.',
+  description = 'Returns signed 8-bit integers from the data in the Blob.',
+  arguments = {
+    offset = {
+      type = 'number',
+      default = '0',
+      description = 'A non-negative byte offset to read from.'
+    },
+    count = {
+      type = 'number',
+      default = '1',
+      description = 'The number of integers to read.'
+    }
+  },
+  returns = {
+    ['...'] = {
+      type = 'number',
+      description = '`count` signed 8-bit integers, from -128 to 127.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'offset', 'count' },
+      returns = { '...' }
+    }
+  },
+  related = {
+    'Blob:getU8',
+    'Blob:getI16',
+    'Blob:getU16',
+    'Blob:getI32',
+    'Blob:getU32',
+    'Blob:getF32',
+    'Blob:getF64'
+  }
+}

+ 11 - 3
api/lovr/data/Blob/getString.lua

@@ -28,11 +28,19 @@ return {
       returns = { 'data' }
     }
   },
+  notes = [[
+    This effectively allocates a new copy of the Blob as a Lua string, so this should be avoided for
+    really big Blobs!
+  ]],
   example = {
-    description = 'Manually copy a file using Blobs:',
+    description = 'Print each byte of the main.lua file:',
     code = [[
-      blob = lovr.filesystem.newBlob('image.png')
-      lovr.filesystem.write('copy.png', blob:getString())
+      blob = lovr.filesystem.newBlob('main.lua')
+      str = blob:getString()
+
+      for i = 1, #str do
+        print(string.byte(str, i))
+      end
     ]]
   }
 }

+ 37 - 0
api/lovr/data/Blob/getU16.lua

@@ -0,0 +1,37 @@
+return {
+  summary = 'Unpack unsigned 16-bit integers from the Blob.',
+  description = 'Returns unsigned 16-bit integers from the data in the Blob.',
+  arguments = {
+    offset = {
+      type = 'number',
+      default = '0',
+      description = 'A non-negative byte offset to read from.'
+    },
+    count = {
+      type = 'number',
+      default = '1',
+      description = 'The number of integers to read.'
+    }
+  },
+  returns = {
+    ['...'] = {
+      type = 'number',
+      description = '`count` unsigned 16-bit integers, from 0 to 65535.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'offset', 'count' },
+      returns = { '...' }
+    }
+  },
+  related = {
+    'Blob:getI8',
+    'Blob:getU8',
+    'Blob:getU16',
+    'Blob:getI32',
+    'Blob:getU32',
+    'Blob:getF32',
+    'Blob:getF64'
+  }
+}

+ 37 - 0
api/lovr/data/Blob/getU32.lua

@@ -0,0 +1,37 @@
+return {
+  summary = 'Unpack unsigned 32-bit integers from the Blob.',
+  description = 'Returns unsigned 32-bit integers from the data in the Blob.',
+  arguments = {
+    offset = {
+      type = 'number',
+      default = '0',
+      description = 'A non-negative byte offset to read from.'
+    },
+    count = {
+      type = 'number',
+      default = '1',
+      description = 'The number of integers to read.'
+    }
+  },
+  returns = {
+    ['...'] = {
+      type = 'number',
+      description = '`count` unsigned 32-bit integers, from 0 to 4294967296.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'offset', 'count' },
+      returns = { '...' }
+    }
+  },
+  related = {
+    'Blob:getI8',
+    'Blob:getU8',
+    'Blob:getI16',
+    'Blob:getU16',
+    'Blob:getI32',
+    'Blob:getF32',
+    'Blob:getF64'
+  }
+}

+ 37 - 0
api/lovr/data/Blob/getU8.lua

@@ -0,0 +1,37 @@
+return {
+  summary = 'Unpack unsigned 8-bit integers from the Blob.',
+  description = 'Returns unsigned 8-bit integers from the data in the Blob.',
+  arguments = {
+    offset = {
+      type = 'number',
+      default = '0',
+      description = 'A non-negative byte offset to read from.'
+    },
+    count = {
+      type = 'number',
+      default = '1',
+      description = 'The number of integers to read.'
+    }
+  },
+  returns = {
+    ['...'] = {
+      type = 'number',
+      description = '`count` unsigned 8-bit integers, from 0 to 255.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'offset', 'count' },
+      returns = { '...' }
+    }
+  },
+  related = {
+    'Blob:getI8',
+    'Blob:getI16',
+    'Blob:getU16',
+    'Blob:getI32',
+    'Blob:getU32',
+    'Blob:getF32',
+    'Blob:getF64'
+  }
+}