The idea is to make is so that you can target players by just typing their name in your code thus making thins like "ulx luarun" a bit more interesting to use.
The metamethod is tried only when key is not present in table. Meaning that the code below will only effect values that are not there meaning that if you have some thing like... Entity(3):Slay() then it won't try to parse "Entity(3)" as a player name even if there is a player under that name. (Correct me if I am wrong.)
_G.__index = function(t, k)
local tr = ULib.getUser(tostring(k),true,nil)
if tr then
return tr
else
return nil
end
end
setmetatable(_G, _G)
or if you like you're code in one line...
_G.__index = function(t, k) local tr = ULib.getUser(tostring(k),true,nil) if tr then return tr else return nil end end setmetatable(_G, _G)
I have also made
"ulx exlua" which pretty much does the same thing without messing with meta tables, and also returns errors cleanly.