Difference between revisions of "Lua:encodeFunction"

From Cheat Engine
Jump to navigation Jump to search
(Undo revision 7035 by Tuzi521 (talk))
(Tag: Undo)
(Major overhaul of the post.)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' encodeFunction(''function'', ''protect'' OPTIONAL) ''':''' string
+
{{CodeBox|'''function''' encodeFunction(''function'') ''':''' string}}
  
Converts a given function into an encoded string that you can pass to [[Lua:decodeFunction|decodeFunction]].
+
Converts a given Lua function into an encoded string.
 +
 
 +
The encoded string can later be passed to [[Lua:decodeFunction|decodeFunction]] to recreate the function.
  
 
===Function Parameters===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
Line 11: Line 13:
 
|-
 
|-
 
|function
 
|function
|function
+
|Function
|The function to encode
+
|The Lua function that should be encoded.
 
|}
 
|}
  
== Examples ==
+
===Returns===
 +
String — The encoded function string.
 +
 
 +
===Examples===
 +
<pre>
 +
local encoded = encodeFunction(function()
 +
  print("Hello from an encoded function")
 +
end)
 +
 
 +
print(encoded)
 +
</pre>
 +
 
 
<pre>
 
<pre>
local function myCoolFunction(str) print(str) end
+
local encoded = encodeFunction(function(value)
print(encodeFunction(myCoolFunction))
+
  return value * 2
 +
end)
 +
 
 +
local decoded = decodeFunction(encoded)
 +
 
 +
print(decoded(21))
 
</pre>
 
</pre>
 +
 
<pre>
 
<pre>
local function myCoolFunction(str) print(str) end
+
local function testFunction()
local encodedFunc = encodeFunction(myCoolFunction)
+
  showMessage("This function was encoded and decoded")
local decodedFunc = decodeFunction(encodedFunc)
+
end
decodedFunc('I have the power!')
+
 
 +
local encoded = encodeFunction(testFunction)
 +
local decoded = decodeFunction(encoded)
 +
 
 +
decoded()
 
</pre>
 
</pre>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
=== Related Functions ===
+
{{LuaIndexBoxNoDescription
* [[Lua:decodeFunction|decodeFunction]]
+
|title=Function Encoding Related Lua Functions
 +
|content=
 +
{{LuaIndexItemNoDescription
 +
|page=encodeFunction
 +
|label=encodeFunction
 +
}}
 +
{{LuaIndexItemNoDescription
 +
|page=decodeFunction
 +
|label=decodeFunction
 +
}}
 +
{{LuaIndexItemNoDescription
 +
|page=encodeFunctionEx
 +
|label=encodeFunctionEx
 +
}}
 +
}}

Revision as of 14:14, 25 June 2026

<> Lua API Reference

function encodeFunction(function) : string

Converts a given Lua function into an encoded string.

The encoded string can later be passed to decodeFunction to recreate the function.

Function Parameters

Parameter Type Description
function Function The Lua function that should be encoded.

Returns

String — The encoded function string.

Examples

local encoded = encodeFunction(function()
  print("Hello from an encoded function")
end)

print(encoded)
local encoded = encodeFunction(function(value)
  return value * 2
end)

local decoded = decodeFunction(encoded)

print(decoded(21))
local function testFunction()
  showMessage("This function was encoded and decoded")
end

local encoded = encodeFunction(testFunction)
local decoded = decodeFunction(encoded)

decoded()

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Function Encoding Related Lua Functions