• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Saving functions in files saveFunction(f,file) & loadFunction(file)

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
In this function i used string.dump
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')
And it will print:
print plx ok
 
Back
Top