That wouldn't give the same result!
If g_weapons is a simple contiguous list (i.e. like an array) then #g_weapons will tell you how many entries it has.
If otoh it is a more complex list then:
local numEntries = 0
for _,v in pairs( g_weapons ) do
if v ~= nil then numEntries = numEntries + 1 end
end
Will tell you how many entries there are in the list.
Been there, done that, got all the T-Shirts!