In this function i used string.dump
better you know it:
You can save functions only from the scripts, (functions inside functions.lua etc) youy cannot save functions like: print, pcall, dofile, doPlayerSay...
Example:
And it will print:
print plx ok
better you know it:
Code:
string.dump (function)
Returns a string containing a binary representation of the given function, so that a later loadstring on this string returns a copy of the function. function must be a [B]Lua function [COLOR="Red"]without upvalues.[/COLOR][/B]
You can save functions only from the scripts, (functions inside functions.lua etc) youy cannot save functions like: print, pcall, dofile, doPlayerSay...
Lua:
function saveFunction(f,file)
local fufu,ok = pcall(string.dump,f)
if not fufu then
return false
end
local i = io.open(file,'wb')
i:write(ok)
i:close()
return true
end
function loadFunction(file)
local q = io.open(file,'rb')
local a = q:read(-1)
q:close()
return loadstring(a)
end
Example:
Code:
function func(...)
print('print plx',...)
end
saveFunction(func,'func')
local f = loadFunction('func')
f('ok')
print plx ok