Difference between revisions of "Lua:encodeFunction"

From Cheat Engine
Jump to navigation Jump to search
(Examples)
m (Added related function template.)
 
(4 intermediate revisions by 2 users not shown)
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===
<pre>
+
String — The encoded function string.
[DISABLE]
+
 
{$lua}
+
===Examples===
decodeFunction("c-n1LOOL7s7-f1V(EzIc7rmRdE2}UZL]4*7$]u3@9aI$LS;:vA6d#D:3!Lj?]WyO)y6FG9owQB5:}/jdPV%k3oF9ebqXc}a]#0{?cz:6$dv[Npz/*?e:@NnY(Aj[NzPo#*uK@lhXaGpP0yoSn0Q}j]0D!;j(HY//54-{mZ,iQ!/Jw!tZ5.#q.BSKuU.g},pNlpeAYFsWz%**(iiW1nD/E!itXbhP1M{Tv9C%?*zuK?/D-R{%(.hO;5fw{RsOk=)i(SaTuYno1!b!sESwC}gW#ZD#fj2TwtJIo4YO]Huk+{s)n/sV8QQaa6r(6rcrbLA^D]:75CfXX-S_#XO)NnFEA(u?Jfi_/Xg=]MEA(ARM/4P?5Wa2i]OIBJ}WPM)J+eDm};/w+0#S*^G6(S7D0udn{/eC?GlO[jDcl]w^G$)#D?RaO:,+%KG9dD1!k]QnQxsW=e6H:iwnv#WCnL^mBjK(3!QK$9Yv80nc]#^W2@J0yWU{4:/ijU)cSXgd3K#d_V]yHq.!ordh*WKReq?59Xw3EA.D.PaC7l/5^A5wZ^B6agiw%ToKUiQ%7](meSy!M=4V$M+#%M_7cPH/_P6ov3ogv#R*NC;il#j(pSRHTY:yllo+znh/Q-QHY][od3)sCYqKJb?Uejpl0GJeR^9*Y21(rk@)Lq$CUreK2J)da6?3k#S}RgW0+)jt14F%:bnvRDbB.lqfJuDHW!YFx)C*FVU,}yL18TNzSlk)ByFY6z2ye,SUAS#-1kZ4Y5rYW-:D-..4s)h(b%jD$uU8fu8upK8p6[W/@97TtoMW/}jq;8ce-sfg[HxH+k2:@_Ebf0H*Pk-XmsakI6BO;)#w12hE/^ttpXlJw0)omu[#oN0=S!//vWiv$3OWO6BuoL}f^zoF*$S/hiu:QaRg4sMV}*wLX05-Td;,%Y(%$qBHgz7t55Ei4K0*=RVMIyrZ8b;BUmRsG;IQQxB1K[N/q*x^KlW5]q_wF}Pn[xfZVviJ?YU9pto,Q3%*3fq0yQP_jA+V_gnh*6B0Q^il!1N{R7FF!Xcrn0#p_lTd7kf+@jP*=]o33o@_+Y/2aSR]1aiWHGh-yq3-^J_$(XI%)m^b}}_3rC,Mg;cHUg)en8kp84_J59a##+)CWwam-r8/4?RTbE#(alQ#m#:0m,-65#?Y/]j{zG{fQ54Y:r/9YW]1Tu%4^8k75_R%[T:b+=2?WkKwk.{Ovp-J!8;HFazNOQ}{ULXP*TfMXl^xL=61]iNrOT93QTKDMSNQm]VYm3a6r?$cr]0RM--02@sgrT")()
+
<syntaxhighlight lang="lua" line>
 +
local encoded = encodeFunction(function()
 +
  print("Hello from an encoded function")
 +
end)
 +
 
 +
print(encoded)
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="lua" line>
 +
local encoded = encodeFunction(function(value)
 +
  return value * 2
 +
end)
 +
 
 +
local decoded = decodeFunction(encoded)
 +
 
 +
print(decoded(21))
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="lua" line>
 +
local function testFunction()
 +
  showMessage("This function was encoded and decoded")
 +
end
 +
 
 +
local encoded = encodeFunction(testFunction)
 +
local decoded = decodeFunction(encoded)
 +
 
 +
decoded()
 +
</syntaxhighlight>
 +
 
 +
{{LuaSeeAlso}}
 +
 
 +
{{EncodeDecode}}

Latest revision as of 00:11, 27 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[edit]

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

Returns[edit]

String — The encoded function string.

Examples[edit]

1 local encoded = encodeFunction(function()
2   print("Hello from an encoded function")
3 end)
4 
5 print(encoded)
1 local encoded = encodeFunction(function(value)
2   return value * 2
3 end)
4 
5 local decoded = decodeFunction(encoded)
6 
7 print(decoded(21))
1 local function testFunction()
2   showMessage("This function was encoded and decoded")
3 end
4 
5 local encoded = encodeFunction(testFunction)
6 local decoded = decodeFunction(encoded)
7 
8 decoded()

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Function Encoding Related Lua Functions