Facepunch / garrysmod-issues

Garry's Mod issue tracker
147 stars 56 forks source link

Some Entity functions return no value/nil instead of NULL or other expected type #3132

Open Kefta opened 7 years ago

Kefta commented 7 years ago

Generating code:

local function TestTable(sMeta, iEnt)
    local pEntity = Entity(iEnt)
    local sFormat = sMeta .. ".%s"

    for k, v in pairs(FindMetaTable(sMeta)) do
        if (string.sub(k, 1, 3) == "Get" and isfunction(v)) then
            local bSuccess, Ret = pcall(v, pEntity)

            if (bSuccess and Ret == nil) then
                print(string.format(sFormat, k))
            end
        end
    end
end

TestTable("Entity", 1) -- player
TestTable("Player", 1)
TestTable("NPC", 173) -- npc_monk
TestTable("Vehicle", 186) -- prop_vehicle_airboat

if (SERVER) then
    TestTable("NextBot", 188) -- npc_tf2_ghost
end

-- CSEnts don't have any Get* functions
robotboy655 commented 7 years ago

I bet there are a lot more functions that do this

Kefta commented 6 years ago

Updated the list

Kefta commented 6 years ago

GetCreator fixed in https://github.com/Facepunch/garrysmod/pull/1381, and GetAnimInfo fixed in https://github.com/Facepunch/garrysmod-issues/issues/3464

robotboy655 commented 6 years ago

I checked all of the engine defined functions and fixed them. Haven't fixed yet the stuff that returns nil cuz those are defined in Lua.

CaptainPRICE commented 5 years ago

Bump.