ObjectType:binary

From Lavish Software Wiki
Jump to navigation Jump to search

Overview

Object Type Vitals
binary
Defined By LavishScript
Inherits none
Reduces To Same as Size
Variable Object Type none
Uses Sub-Types no
C/C++ Type LSBinary *

Positions within a binary object are 1-based.

Members

  • uint Size: Size of the buffer
  • intptr Int[#]: An int at byte position # of this buffer
  • byteptr Byte[#]: A byte at position # of this buffer
  • floatptr Float[#]: A float at byte position # of this buffer
  • int64ptr Int64[#]: An int64 at byte position # of this buffer
  • string String[#]: A string at byte position # of this buffer. NULL if the string is not null-terminated within the size of the buffer
  • uintptr Uint[#]: A uint at byte position # of this buffer
  • boolptr Bool[#]: A bool at byte position # of this buffer

Methods

  • Resize[#]: Resizes the buffer to this many bytes. Minimum 1, maximum 4194304 (4MB) -- if you need larger for some reason, please let us know. This is a sanity check
  • Copy[buffer,#]: Copies # bytes from another buffer to position 1 of this buffer

Examples

Example code
function main() 
{ 
   Declare Buffer binary
   Declare File file test.dat 
    
   echo Filename=${File.Path}${File.Filename} 
   echo Opened=${File:Open(exists)} 
   echo Write=${File:Write["Line One...\n"](exists)} 
   echo Position=${File.Position} 
   echo Write=${File:Write["Line Two!\n"](exists)} 
   echo Position=${File.Position} 
   echo Truncate=${File:Truncate(exists)} 
   echo Size=${File.Size} 
   File:Close 
   echo Closed 
 
   echo Filename=${File.Path}${File.Filename} 
   echo Opened Readonly=${File:Open[readonly](exists)} 
   echo Write=${File:Write["Overwriting Line One?\n"](exists)} 
   echo Position=${File.Position} 
   echo Read=${File.Read} 
   echo Position=${File.Position} 
   echo Read=${File.Read} 
   echo Position=${File.Position} 
   File:Close 
   echo Closed 

   declare FP filepath "c:/program files/innerspace/scripts"
   echo FileExists[test.iss] = ${FP.FileExists[test.iss]}
   echo Path = ${FP.Path}
   echo PathExists = ${FP.PathExists}
   echo AbsolutePath = ${FP.AbsolutePath}

   echo Filename=${File.Path}${File.Filename} 
   echo Opened Readonly=${File:Open[readonly](exists)} 
   echo ReadBinary=${File.ReadBinary[Buffer,${File.Size}]} 
   echo Null terminating... 
   Buffer.Byte[${File.Size}]:Set[0] 
   echo String=${Buffer.String[1]} 
   File:Close 
   echo Closed 
 
   echo Filename=${File.Path}${File.Filename} 
   echo Opened=${File:Open(exists)} 
   Buffer.Int[1]:Set[12345678] 
   echo WriteBinary=${File:WriteBinary[Buffer,${File.Size}](exists)} 
   File:Close 
   echo Closed 
} 
Output
Filename=C:/Program Files/InnerSpace/test.dat
Opened=TRUE
Write=TRUE
Position=12
Write=TRUE
Position=22
Truncate=TRUE
Size=22
Closed
Filename=C:/Program Files/InnerSpace/test.dat
Opened Readonly=TRUE
Write=NULL
Position=0
Read=Line One...   

Position=12
Read=Line Two! 

Position=22
Closed
FileExists[test.iss] = TRUE
Path = c:/program files/innerspace/scripts
PathExists = TRUE
AbsolutePath = c:/program files/innerspace/scripts
Filename=C:/Program Files/InnerSpace/test.dat
Opened Readonly=TRUE
ReadBinary=22
Null terminating...
String=NULL
Closed
Filename=C:/Program Files/InnerSpace/test.dat
Opened=TRUE
WriteBinary=TRUE
Closed

See Also

LavishScript Object Types