67 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
		
		
			
		
	
	
			67 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
|  | /* | ||
|  | 文件名:BlobExClass.nut | ||
|  | 路径:BaseClass/BaseTool/BlobExClass.nut | ||
|  | 创建日期:2024-05-07	17:34 | ||
|  | 文件用途:拓展的Blob类 | ||
|  | */ | ||
|  | class blobex extends blob { | ||
|  | 
 | ||
|  |     //-----------------Metamethods--------------------// | ||
|  |     function _typeof() { | ||
|  |         return "blobex"; | ||
|  |     } | ||
|  |     //-----------------Metamethods--------------------// | ||
|  | 
 | ||
|  |     constructor(arg) { | ||
|  |         //通过blob构造 | ||
|  |         if (typeof arg == "blob") { | ||
|  |             base.constructor(arg.len()); | ||
|  |             writeblob(arg); | ||
|  |         } | ||
|  |         //直接构造 | ||
|  |         else { | ||
|  |             base.constructor(arg); | ||
|  |         } | ||
|  |     } | ||
|  | 
 | ||
|  |     function writeblob(B) { | ||
|  |         base.writeblob(B); | ||
|  |         seek(0); | ||
|  |     } | ||
|  | 
 | ||
|  |     function GetUShort() { | ||
|  |         return readn('w'); | ||
|  |     } | ||
|  | 
 | ||
|  |     function GetShort() { | ||
|  |         return readn('s'); | ||
|  |     } | ||
|  | 
 | ||
|  |     function charPtrToInt(arr) { | ||
|  |         local value = ((arr[0]) << 0) | | ||
|  |             ((arr[1]) << 8) | | ||
|  |             ((arr[2]) << 16) | | ||
|  |             ((arr[3]) << 24); | ||
|  |         return value; | ||
|  |     } | ||
|  | 
 | ||
|  |     function GetInt() { | ||
|  |         local CurTPos = tell(); | ||
|  |         local Ret = charPtrToInt([this[CurTPos], this[CurTPos + 1], this[CurTPos + 2], this[CurTPos + 3]]); | ||
|  |         seek(4, 'c'); | ||
|  |         return Ret; | ||
|  |     } | ||
|  | 
 | ||
|  |     function Get256() { | ||
|  |         local Buf = readn('c'); | ||
|  |         return (256.0 + Buf.tofloat()) % 256.0; | ||
|  |     } | ||
|  | 
 | ||
|  |     function GetFloat() { | ||
|  |         return readn('f'); | ||
|  |     } | ||
|  | 
 | ||
|  |     function GetString(count) { | ||
|  |         return stream_myreadstring(count); | ||
|  |     } | ||
|  | } |