Today I want to explain how to protect your code from prying eyes, first we have to install the lua 5.0 support on freebsd if you do not have it in this way:
Code:
# cd /usr/ports/lang/lua50 && make install clean
Code:
# /usr/local/bin/lua50/luac -o myFile myFile.lua
for example of an application we can use my tournament quest:

we can see the quest using various functions written by me
functions:
Code:
TORNEO_READ = 0
TORNEO_PLUS = 1
TORNEO_NEW = 3
TORNEO_NEXT = 4
TORNEO_MEMBER = 1
TORNEO_REGISTRED = 2
TORNEO_START = 3
TORNEO_FINISH = 4
TORNEO_STAGE = 5
TORNEO_ROUND = 6
function torneo_open_regi()
local TORNEO_PATH = "locale/italy/quest/object/torneo/"
local TORNEO_FILE = "torneo_stage_*"
os.execute("cd "..TORNEO_PATH.." && rm -rf "..TORNEO_FILE)
game.set_event_flag("torneo_close", 0)
end
function torneo_round(number)
local stage = { 8,16,24,32,40,48,56,64 }
local x = 1
while true do
if stage[x] == nil then break end
if number <= stage[x] then
return x
end
x = x + 1
end
end
function torneo_tool(linea, stage, round, modo)
local TORNEO_PATH = "locale/italy/quest/object/torneo/"
local TORNEO_FILE = "torneo_stage_"..stage.."_round_"..round..".txt"
local x = 1
local file
local newRound
local result
if modo == 0 then
file = io.open(TORNEO_PATH..TORNEO_FILE, "r")
while true do
local line = file:read("*l")
if line == nil then
break
end
local text = string.gsub(line, "\n", "")
if x == linea then
io.close(file)
return text
end
x = x + 1
end
io.close(file)
elseif modo == 1 then
file = io.open(TORNEO_PATH..TORNEO_FILE, "a+")
file:write(linea.."\n")
io.close(file)
elseif modo == 2 then
if round <= 2 then
newRound = 1
elseif round <= 4 then
newRound = 2
elseif round <= 6 then
newRound = 3
elseif round <= 8 then
newRound = 4
end
local TORNEO_NEWFILE = "torneo_stage_"..stage.."_round_"..newRound..".txt"
file = io.open(TORNEO_PATH..TORNEO_NEWFILE, "a+")
file:write(linea.."\n")
io.close(file)
return newRound
end
end
function torneo_data(linea, modo)
local TORNEO_PATH = "locale/italy/quest/object/torneo/"
local TORNEO_FILE = "torneo.txt"
local x = 1
local file = ""
if modo == TORNEO_READ then
file = io.open(TORNEO_PATH..TORNEO_FILE, "r")
while true do
local line = file:read("*l")
if line == nil then
break
end
local text = string.gsub(line, "\n", "")
if x == linea then
io.close(file)
return text
end
x = x + 1
end
io.close(file)
elseif modo == TORNEO_PLUS then
local linee = {}
local x = 1
local y = 1
file = io.open(TORNEO_PATH..TORNEO_FILE, "r")
while true do
linee[x] = file:read("*l")
if linee[x] == nil then
break
end
x = x + 1
end
io.close(file)
os.rename(TORNEO_PATH..TORNEO_FILE, TORNEO_PATH..TORNEO_FILE..".BAK")
local update = io.open(TORNEO_PATH..TORNEO_FILE, "a+")
while true do
if linee[y] == nil then break end
if y == linea then
local newPoint = tonumber(linee[y]) + 1
update:write(newPoint.."\n")
else
update:write(linee[y].."\n")
end
io.flush()
y = y + 1
end
io.close(update)
elseif modo == TORNEO_NEXT then
local linee = {}
local x = 1
local y = 1
file = io.open(TORNEO_PATH..TORNEO_FILE, "r")
while true do
linee[x] = file:read("*l")
if linee[x] == nil then
break
end
x = x + 1
end
io.close(file)
local newMember = tonumber(linee[1])/2
local newFinish = 0
local newStage = tonumber(linee[5])+1
local newRound = 1
local newStart = tonumber(linee[3])+1
local update = io.open(TORNEO_PATH..TORNEO_FILE, "w+")
update:write(newMember.."\n"..linee[2].."\n"..newStart.."\n"..newFinish.."\n"..newStage.."\n"..newRound.."\n")
io.close(update)
elseif modo == TORNEO_NEW then
file = io.open(TORNEO_PATH..TORNEO_FILE, "w+")
file:write(linea.."\n0\n0\n0\n1\n1\n")
io.close(file)
end
end
function torneo_opp(posizione, stage, round)
local member = {}
local x = 1
local sfidanti = tonumber(torneo_member(stage, round))/2
while true do
member[x] = torneo_tool(x, stage, round, 0)
if member[x] == nil then break end
x = x + 1
end
local opps = sfidanti + posizione
local chll = posizione - sfidanti
if posizione <= sfidanti then
return member[opps]
else
return member[chll]
end
end
function torneo_member(stage, round)
local TORNEO_PATH = "locale/italy/quest/object/torneo/"
local TORNEO_FILE = "torneo_stage_"..stage.."_round_"..round..".txt"
local x = 1
local file = io.open(TORNEO_PATH..TORNEO_FILE, "r")
while true do
local line = file:read("*l")
if line == nil then break end
x = x + 1
end
io.close(file)
local result = x - 1
return result
end
function torneo_number(name, stage, round)
local player = {}
local x = 1
while true do
player[x] = torneo_tool(x, stage, round, 0)
if player[x] == name then break end
x = x + 1
end
return x
end
simple compiling the source "torneo_lib.lua" as described previously we get a file like this:

now we need only to put in questlib.lua the line(I created the lib directory but we can put it anywhere):
Code:
dofile("locale/italy/quest/lib/torneo_lib");
i hope be useful
enjoy
d3m0n3






