• 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!

Things you may not know.

Mkalo

ボーカロイド
Senator
Joined
Jun 1, 2011
Messages
1,118
Solutions
55
Reaction score
946
Location
Japan
If you know about debug.setmetatable, you can leave now. If you didn't here it is some nice things you can do with it:
Code:
COUNTER = 1

function toTable(object, name)
    if not name then
        name = COUNTER
        COUNTER = COUNTER+1
    end
    _G["__" .. name] = _G["__" .. name] or {__name = name}
    debug.setmetatable(object, {__newindex = function (a, b, c) rawset(_G["__" .. name], b, c) end, __index = function(a, b) return rawget(_G["__" .. name], b) end, __len = function() return #_G["__" .. name] end})
    return object
end

function getTable(object)
    if object.__name and _G["__" .. object.__name] then
        return _G["__" .. object.__name]
    end
end

local a = 10
toTable(a)
debug.getmetatable(a).__call = function() print("Why are you calling a number value? XD") end
a[1] = 2
a[2] = 4
a[3] = 6

print(a) -- 10
print(a[1], a[2], a[3]) -- 2    4    6
print(table.concat(getTable(a), ", ")) -- 2, 4, 6
a() -- Why are you calling a number value? XD

That's it bye.
 
Code:
print("Recursive:");
(function(t) local function recursive(i) if t[i] then print(t[i]) return recursive(i+1) end end recursive(1) end)({1, 2, 3, 4, 5});
print("For loop:");
(function(t) for i = 1, #t do print(t[i]) end end)({1, 2, 3, 4, 5});
(function(i, m) if i <= m then print(i) return debug.getinfo(1).func(i + 1, m) end end )(1, 10);

Thats actually pretty cool and yes its Lua :|
 
Last edited:
How to see every function call in your server: (Works for any version, this is Lua debug functions.)
Code:
local ignore = {"=%[C%]", "@data/lib/.+"}
function isInPatternArray(str, array)
   for i, x in pairs(array) do
     if str:match(x) then
       return true
     end
   end

   return false
end

debug.sethook(function()
   local info = debug.getinfo(2)
   if info and info.source and not isInPatternArray(info.source, ignore) then
     if info.source == "=[C]" then
       print(info.name or "=[C]")
     else
       print(info.source)
     end
   end
end, "c")

In some place of your lib files or a new lib file whatever will do.
What you will see:
fjJkc1V.png

With this you can see everything I did while online.

Did some changes to print the name of C functions however I would let those ignoreds however if you remove it from the table of ignored you will see this:
http://pastebin.com/bMAHaeRN

And thats just from me logging in and out, so not that good :)
 
Last edited:
How to see every function call in your server: (Works for any version, this is Lua debug functions.)
Code:
local ignore = {"=%[C%]", "@data/lib/.+"}
function isInPatternArray(str, array)
   for i, x in pairs(array) do
     if str:match(x) then
       return true
     end
   end

   return false
end

debug.sethook(function()
   local info = debug.getinfo(2)
   if info and info.source and not isInPatternArray(info.source, ignore) then
     if info.source == "=[C]" then
       print(info.name or "=[C]")
     else
       print(info.source)
     end
   end
end, "c")

In some place of your lib files or a new lib file whatever will do.
What you will see:
fjJkc1V.png

With this you can see everything I did while online.

Did some changes to print the name of C functions however I would let those ignoreds however if you remove it from the table of ignored you will see this:
http://pastebin.com/bMAHaeRN

And thats just from me logging in and out, so not that good :)

Im testing it but when i open the server, in console appears too many prints about npc's with endless. How can i fix it?
 
me too :/
Again, thats why I placed the "ignore" table. You should add patterns that you want to ignore to avoid spam.
Code:
local ignore = {"=%[C%]", "@data/lib/.+"}

Thats ignoring C function calls and lib function calls.
 
Again, thats why I placed the "ignore" table. You should add patterns that you want to ignore to avoid spam.
Code:
local ignore = {"=%[C%]", "@data/lib/.+"}

Thats ignoring C function calls and lib function calls.
Yes, i could solve it minutes later. Any way, thanks.
 
Code:
print("Recursive:");
(function(t) local function recursive(i) if t[i] then print(t[i]) return recursive(i+1) end end recursive(1) end)({1, 2, 3, 4, 5});
print("For loop:");
(function(t) for i = 1, #t do print(t[i]) end end)({1, 2, 3, 4, 5});
(function(i, m) if i <= m then print(i) return debug.getinfo(1).func(i + 1, m) end end )(1, 10);

Thats actually pretty cool and yes its Lua :|
Okay, call me a noob :p
Where should i put this script? It seems pretys usefull
 
Okay, call me a noob :p
Where should i put this script? It seems pretys usefull
This script is just to show a neat usage of closures and debug.getinfo. This script is useless, just going to print stuff.
 
Code:
Code:
local ignore = {"=%[C%]", "@data/lib/.+"}
function isInPatternArray(str, array)
   for i, x in pairs(array) do
     if str:match(x) then
       return true
     end
   end

   return false
end

debug.sethook(function()
   local info = debug.getinfo(2)
   if info and info.source and not isInPatternArray(info.source, ignore) then
     if info.source == "=[C]" then
       print(info.name or "=[C]")
     else
       print(info.source)
     end
   end
end, "c")

Please
Where I put this for see the logs?
 
Back
Top