ULX

Author Topic: Table of convars?  (Read 7430 times)

0 Members and 1 Guest are viewing this topic.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Table of convars?
« on: April 23, 2008, 04:53:59 PM »
While tinkering with Umotd, I discovered hook.GetTable(). Not useful for me at the moment, but it gave me an idea towards something else I want.

Is there a table, or command that would return a list (string, table or otherwise) of console variables?
I'd need to be able to store these in a lua.
I'm particularly looking for a way to loop through the convar list looking for specific ones.

Any Gmod Lua coders out there know of anything I might use?
I looked at Garry's code.garrysmod.com for the ConvarExist, but it's apparently hard coded into Gmod and not a lua function. I'd hoped it just searched a lua stored table.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Table of convars?
« Reply #1 on: April 23, 2008, 06:44:43 PM »
Rewrite the cvar creation functions. You probably won't get all of them but you'll get most of them.
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Table of convars?
« Reply #2 on: April 23, 2008, 08:52:03 PM »
Interesting idea.
And for the main function of what I'd want, I think it would work 100% (making an automatic table of sbox_ and sbox_wiremax_ commands)
Actually, wouldn't Gmod lua functions execute before any others? So even if I somehow overwrote CreateConVar, sbox_ standard from server.cfg wouldn't use mine, but use Garry's original?
As for the wire mod, seems I'd have a 50/50 chance whether my function got used first.

And, with my inexperience here, how would I do it?

CreateConvar is a server side function, and doesn't seem to have any lua. Probably like ConvarExists...it's in the static gmod code.

Without having any lua to base it on, how would I go about doing it?
I've looked at our ULib shared IsSuperAdmin/Admin, and see a meta, but I'm not sure how to still have the variables passed to it run/get added after I added them to my tables.
There is a FindMetaTable("ConVar") to work with, but no CreateConVar function within it.
Code: [Select]
] lua_run convars = FindMetaTable("ConVar") PrintTable(convars)
> convars = FindMetaTable("ConVar") PrintTable(convars)...
MetaID = 25
GetName = function: 03B41D40
MetaName = ConVar
GetFloat = function: 03B41D88
GetInt = function: 03B41DA0
GetBool = function: 03B41DD0
GetString = function: 03B41E00
GetDefault = function: 03B41E18
__index:
MetaID = 25
GetName = function: 03B41D40
MetaName = ConVar
GetFloat = function: 03B41D88
GetInt = function: 03B41DA0
GetBool = function: 03B41DD0
GetString = function: 03B41E00
GetDefault = function: 03B41E18
__index = table: 03F3CD60
GetHelpText = function: 03B41D70
GetHelpText = function: 03B41D70

Any guidance would be appreciated.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Table of convars?
« Reply #3 on: April 23, 2008, 10:04:35 PM »
Doesn't matter if it's based in the lua engine directly. You keep a reference to the old function, then make your own that reads what you want and calls the original. :)
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Table of convars?
« Reply #4 on: April 24, 2008, 06:09:11 PM »
Doesn't matter if it's based in the lua engine directly. You keep a reference to the old function, then make your own that reads what you want and calls the original. :)

Like so?
Code: [Select]
MyConVarsTbl = {}
MyConCmd = CreateConVar()
local meta=FindMetaTable("ConVar")
function meta:CreateConVar( var, val )
     //my code creating table
     table.Add( MyConVarsTbl, { var = val } )
    //Normal call
    MyConCmd(var, val)
end
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Table of convars?
« Reply #5 on: April 26, 2008, 09:00:29 AM »
Like so?
Code: [Select]
MyConVarsTbl = {}
MyConCmd = CreateConVar()
local meta=FindMetaTable("ConVar")
function meta:CreateConVar( var, val )
     //my code creating table
     table.Add( MyConVarsTbl, { var = val } )
    //Normal call
    MyConCmd(var, val)
end

No need to use find meta table, and it should be myConCmd = ConVar.CreateConVar(), but yes.
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Table of convars?
« Reply #6 on: April 26, 2008, 12:25:32 PM »
Thanks for the idea. Not sure about replacing Garry's default commands. Would seem better for all devs if Garry did this already, much like hook.GetTable(), but ConVar.GetTable() instead.
I'm concerned with breaking others, and of course, at what point this loads. Currently, all my code loads from Ulib modules, which seems to load after ulx and wire (and probably others)

There's a command when finishing singleplayer load that gets echoed to console, similiar to something like
---- 48939843 client convars loaded. Use spewconvars_cl to display the list -------
(not exactly that command, but its similiar) It prints out a long list of convars.
I had hoped that would have been from a table.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Table of convars?
« Reply #7 on: April 26, 2008, 01:08:55 PM »
That's the wrong convar anyways. It's just the player info stuff. :P
Experiencing God's grace one day at a time.