General > Developers Corner

Table of convars?

(1/2) > >>

JamminR:
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.

Megiddo:
Rewrite the cvar creation functions. You probably won't get all of them but you'll get most of them.

JamminR:
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: ---] 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

--- End code ---

Any guidance would be appreciated.

Megiddo:
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. :)

JamminR:

--- Quote from: Megiddo 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. :)

--- End quote ---

Like so?

--- Code: ---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

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version