| 
									
										
										
										
											2024-09-27 14:04:23 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 文件名:MemoryClass.nut | 
					
						
							|  |  |  | 路径:Base/_Tool/MemoryClass.nut | 
					
						
							|  |  |  | 创建日期:2024-09-24	08:22 | 
					
						
							|  |  |  | 文件用途: | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Memory { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function alloc(Size) { | 
					
						
							| 
									
										
										
										
											2024-11-15 10:32:19 +08:00
										 |  |  |         return NativePointer(Size.tostring()); | 
					
						
							| 
									
										
										
										
											2024-09-27 14:04:23 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function allocUtf8String(Str) { | 
					
						
							|  |  |  |         return NativePointer(Str_Ptr(Str)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NativePointer { | 
					
						
							| 
									
										
										
										
											2025-07-05 22:28:57 +08:00
										 |  |  |     //大小 | 
					
						
							|  |  |  |     Size = -1; | 
					
						
							| 
									
										
										
										
											2024-09-27 14:04:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     C_Object = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(T) { | 
					
						
							|  |  |  |         if (type(T) == "integer") { | 
					
						
							| 
									
										
										
										
											2024-11-15 10:32:19 +08:00
										 |  |  |             C_Object = L_sq_I2P(T); | 
					
						
							| 
									
										
										
										
											2024-09-27 14:04:23 +08:00
										 |  |  |         } else if (type(T) == "userdata") { | 
					
						
							|  |  |  |             C_Object = T; | 
					
						
							| 
									
										
										
										
											2024-11-15 10:32:19 +08:00
										 |  |  |         } else if (type(T) == "string") { | 
					
						
							|  |  |  |             C_Object = Sq_New_Point(T.tointeger()); | 
					
						
							| 
									
										
										
										
											2025-07-05 22:28:57 +08:00
										 |  |  |             Size = T; | 
					
						
							| 
									
										
										
										
											2024-11-15 10:32:19 +08:00
										 |  |  |             //注册销毁伪析构 | 
					
						
							|  |  |  |             Register_Destruction(C_Object, this); | 
					
						
							| 
									
										
										
										
											2024-09-27 14:04:23 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function add(intoffset) { | 
					
						
							|  |  |  |         this.C_Object = L_sq_I2P(L_sq_P2I(this.C_Object) + intoffset); | 
					
						
							|  |  |  |         return this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function sub(intoffset) { | 
					
						
							|  |  |  |         this.C_Object = L_sq_I2P(L_sq_P2I(this.C_Object) - intoffset); | 
					
						
							|  |  |  |         return this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeByteArray(arr) { | 
					
						
							|  |  |  |         Sq_Memory_WriteByteArr(this.C_Object, arr); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readByteArray(size) { | 
					
						
							|  |  |  |         local PointB = Sq_Point2Blob(this.C_Object, size); | 
					
						
							|  |  |  |         local arr = []; | 
					
						
							|  |  |  |         foreach(value in PointB) { | 
					
						
							|  |  |  |             arr.append(value); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return arr; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function write(value, type) { | 
					
						
							|  |  |  |         local Buf = blob(0); | 
					
						
							|  |  |  |         Buf.writen(value, type); | 
					
						
							|  |  |  |         local arr = []; | 
					
						
							|  |  |  |         foreach(value in Buf) { | 
					
						
							|  |  |  |             arr.append(value); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         writeByteArray(arr); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeS8(value) { | 
					
						
							|  |  |  |         write(value, 'c'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeU8(value) { | 
					
						
							|  |  |  |         write(value, 'b'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeS16(value) { | 
					
						
							|  |  |  |         write(value, 's'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeU16(value) { | 
					
						
							|  |  |  |         write(value, 'w'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeS32(value) { | 
					
						
							|  |  |  |         write(value, 'i'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeU32(value) { | 
					
						
							|  |  |  |         write(value, 'i'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeShort(value) { | 
					
						
							|  |  |  |         write(value, 's'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeUShort(value) { | 
					
						
							|  |  |  |         write(value, 'w'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeInt(value) { | 
					
						
							|  |  |  |         write(value, 'i'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeUInt(value) { | 
					
						
							|  |  |  |         write(value, 'i'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeFloat(value) { | 
					
						
							|  |  |  |         write(value, 'f'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function writeDouble(value) { | 
					
						
							|  |  |  |         write(value, 'd'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function read(type) { | 
					
						
							| 
									
										
										
										
											2024-09-29 16:52:10 +08:00
										 |  |  |         local Buf = Sq_Point2Blob(L_sq_P2I(this.C_Object), 4); | 
					
						
							| 
									
										
										
										
											2024-09-27 14:04:23 +08:00
										 |  |  |         return Buf.readn(type); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readS8() { | 
					
						
							|  |  |  |         return read('c'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readU8() { | 
					
						
							|  |  |  |         return read('b'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readS16() { | 
					
						
							|  |  |  |         return read('s'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readU16() { | 
					
						
							|  |  |  |         return read('w'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readS32() { | 
					
						
							|  |  |  |         return read('i'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readU32() { | 
					
						
							|  |  |  |         return read('i'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readShort() { | 
					
						
							|  |  |  |         return read('s'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readUShort() { | 
					
						
							|  |  |  |         return read('w'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readInt() { | 
					
						
							|  |  |  |         return read('i'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readUInt() { | 
					
						
							|  |  |  |         return read('i'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readFloat() { | 
					
						
							|  |  |  |         return read('f'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readDouble() { | 
					
						
							|  |  |  |         return read('d'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readUnicodeString(...) { | 
					
						
							|  |  |  |         if (vargc > 0) { | 
					
						
							|  |  |  |             return Sq_Memory_ReadString(this.C_Object, vargv[0]); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return Sq_Memory_ReadString(this.C_Object); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readUtf8String(...) { | 
					
						
							|  |  |  |         if (vargc > 0) { | 
					
						
							|  |  |  |             return Sq_Memory_ReadStringByUtf8(this.C_Object, vargv[0]); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return Sq_Memory_ReadStringByUtf8(this.C_Object); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readBig5String(...) { | 
					
						
							|  |  |  |         if (vargc > 0) { | 
					
						
							|  |  |  |             return Sq_Memory_ReadStringByBig5(this.C_Object, vargv[0]); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return Sq_Memory_ReadStringByBig5(this.C_Object); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function readPointer() { | 
					
						
							|  |  |  |         return Sq_ReadPoint(this.C_Object); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function tostring() { | 
					
						
							|  |  |  |         return this.C_Object.tostring(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |