• Get all function arguments
    15 replies, posted
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.
[lua] function randomfunc(...) print(unpack(arg)) end [/lua] -from ¦FJ¦
[lua]function variadicfunc(...) print(...) end[/lua] You can do that too, I think. [editline]09:01PM[/editline] 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 ;) Requested it because Conna might have comprimised my account.
I also prefer to use arg for the same reasons, Just giving other options.
Thanks
arg is deprecated.
[code]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)... A<TAB>C<TAB>B<TAB>1<TAB>2<TAB>3<TAB>4[/code] [editline]09:11PM[/editline] [code]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)... 1<TAB>2<TAB>3<TAB>4[/code] [editline]09:12PM[/editline] They're exactly the same. One is as good as the other.
Not really, with arg you can do a lot more than [b]...[/b]. 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( ... ) end[/lua] or [lua]chat.AddText = function( ... ) print( ... ) end[/lua] 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. [editline]04:15PM[/editline] Ninja'd. :eng99:
Thanks, i need override because there is no hooks to use with original chat.AddText for making custom chatbox [editline]06:36AM[/editline] 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: [url]http://wiki.garrysmod.com/?title=Gamemode.ChatText[/url]
Sorry, you need to Log In to post a reply to this thread.