Difference between revisions of "Lua:registerCustomTypeLua"

From Cheat Engine
Jump to navigation Jump to search
(Replaced content with '<span style="font-size:25px;color:red">Sorry! Content not available.</span>')
m
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<span style="font-size:25px;color:red">Sorry! Content not available.</span>
+
[[Category:Lua]]
 +
'''function''' registerCustomTypeLua(''TypeName'', ''ByteCount'', ''BytesToValueFunction'', ''ValueToBytesFunction'', [''IsFloat'']) ''':''' CustomType
 +
 
 +
Registers a custom value type for Cheat Engine memory records, using Lua functions for conversion between bytes and values.
 +
 
 +
The bytes-to-value function should be defined as <code>function bytestovalue(b1, b2, ...)</code> and return the interpreted value. 
 +
The value-to-bytes function should be defined as <code>function valuetobytes(value)</code> and return the bytes to write (as multiple return values).
 +
 
 +
===Function Parameters===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Parameter
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|TypeName
 +
|String
 +
|The name of the custom type.
 +
|-
 +
|ByteCount
 +
|Integer
 +
|The number of bytes this type occupies.
 +
|-
 +
|BytesToValueFunction
 +
|Function
 +
|A Lua function that takes <code>ByteCount</code> arguments and returns the interpreted value.
 +
|-
 +
|ValueToBytesFunction
 +
|Function
 +
|A Lua function that takes a value and returns <code>ByteCount</code> bytes (as multiple return values).
 +
|-
 +
|IsFloat
 +
|Boolean (optional)
 +
|Set to true if the type should be treated as a floating point value.
 +
|}
 +
 
 +
===Returns===
 +
CustomType — The registered custom type object.
 +
 
 +
===Examples===
 +
<pre>
 +
-- Example: Register a 3-byte integer type
 +
function myBytesToValue(b1, b2, b3)
 +
  return b1 + (b2 << 8) + (b3 << 16)
 +
end
 +
 
 +
function myValueToBytes(val)
 +
  local b1 = val & 0xFF
 +
  local b2 = (val >> 8) & 0xFF
 +
  local b3 = (val >> 16) & 0xFF
 +
  return b1, b2, b3
 +
end
 +
 
 +
local myType = registerCustomTypeLua("3ByteInt", 3, myBytesToValue, myValueToBytes)
 +
</pre>
 +
 
 +
{{LuaSeeAlso}}
 +
 
 +
=== Related Functions ===
 +
* [[Lua:registerCustomTypeAutoAssembler|registerCustomTypeAutoAssembler]]
 +
* [[Lua:getCustomType|getCustomType]]

Latest revision as of 18:41, 11 July 2025

function registerCustomTypeLua(TypeName, ByteCount, BytesToValueFunction, ValueToBytesFunction, [IsFloat]) : CustomType

Registers a custom value type for Cheat Engine memory records, using Lua functions for conversion between bytes and values.

The bytes-to-value function should be defined as function bytestovalue(b1, b2, ...) and return the interpreted value. The value-to-bytes function should be defined as function valuetobytes(value) and return the bytes to write (as multiple return values).

Function Parameters[edit]

Parameter Type Description
TypeName String The name of the custom type.
ByteCount Integer The number of bytes this type occupies.
BytesToValueFunction Function A Lua function that takes ByteCount arguments and returns the interpreted value.
ValueToBytesFunction Function A Lua function that takes a value and returns ByteCount bytes (as multiple return values).
IsFloat Boolean (optional) Set to true if the type should be treated as a floating point value.

Returns[edit]

CustomType — The registered custom type object.

Examples[edit]

-- Example: Register a 3-byte integer type
function myBytesToValue(b1, b2, b3)
  return b1 + (b2 << 8) + (b3 << 16)
end

function myValueToBytes(val)
  local b1 = val & 0xFF
  local b2 = (val >> 8) & 0xFF
  local b3 = (val >> 16) & 0xFF
  return b1, b2, b3
end

local myType = registerCustomTypeLua("3ByteInt", 3, myBytesToValue, myValueToBytes)

See also[edit]

Related Functions[edit]