Get all function arguments

Is there any method to get all function arguments(endless amount), because i writing my own chatbox and want to override chat.AddText to parse it.

function randomfunc(…)

-from ¦FJ¦

[lua]function variadicfunc(…)

You can do that too, I think.


arg == {…}
unpack(arg) == …

It’s a matter of preferance. I prefer using arg since, for one it’s used in standard Lua. Second of all, you can use it as a table rather than a bunch of args.

If you’re wondering, yes, I’m banned again :wink: Requested it because Conna might have comprimised my account.

I also prefer to use arg for the same reasons, Just giving other options.


arg is deprecated.

21:09:02 lua_run function a(...) print(unpack(arg)) end
21:09:02 Rcon: "lua_run function a(...) print(unpack(arg)) end"
21:09:03 > function a(...) print(unpack(arg)) end...
21:09:20 lua_run a("A" , "C" , "B" , 1 , 2, 3 , 4)
21:09:20 Rcon: "lua_run a("A" , "C" , "B" , 1 , 2, 3 , 4)"
21:09:20 > a("A" , "C" , "B" , 1 , 2, 3 , 4)...


21:10:56 Rcon: "lua_run function b(...) print(...) end"
21:10:56 > function b(...) print(...) end...
21:11:06 lua_run b(1 , 2 , 3 , 4)
21:11:06 Rcon: "lua_run b(1 , 2 , 3 , 4)"
21:11:07 > b(1 , 2 , 3 , 4)...


They’re exactly the same. One is as good as the other.

Not really, with arg you can do a lot more than . With … you can only forward arguments.

So “arg” and “…” are actually referenced values in Lua? I learned something today. Thank you, Overv.

New question - how to find chat metatable(and override chat.AddText function)?

chat = FindMetaTable(“chat”) and
chat = FindMetaTable(“Chat”) not working.(returns nil)

chat is not a metatable, you’d just do this:

[lua]function chat.AddText( … )
print( … )


[lua]chat.AddText = function( … )
print( … )

What do you want to override chat.AddText for?

chat is a library, not a metatable. Metatables are used with objects, such as Players, NPCs, or Entities. They can also be used with what I like to call theoretical objects, such as text, but this isn’t an instance where that is so.


Ninja’d. :eng99:

Thanks, i need override because there is no hooks to use with original chat.AddText for making custom chatbox


One more question - string.len sometimes returning length = 2 for some symbols. How to detect those symbols?

I’m pretty sure there is in fact a hook that detects text added with chat.AddText. I don’t remember which exactly though.

This handles join and leave messages and I think the ChatPrint messages, but doesn’t handle chat.AddText: