LUA Error: attempt to index a nil value @6:16

LUA Error: attempt to index a nil value @6:16

我正在尝试通过发送请求来检索 Entryhandle UUID。但是,我每次都会收到此错误。谁能帮我解决或指出我哪里出错了?

local config={}

config.mcast_mac = "00:0a:cd:16:da:f1"


function rpc:epm()                                                                    


 local pkt = CreateFromPath("ethernet/ip/udp/dcerpc/epm")

 --[[data is put here]]


 SendAndWait(pkt, function(res)
local epm = res.get_layer("epm")
--[[data is put here--]]
handle = epm.EntryHandleUUID.to_string()

print("EntryHandleUUID:",handle)

 end



 end,2000)

  return handle

  end 

此代码无效 Lua 代码。假设从 print 之后的行中删除 end。 要找出您尝试访问 nil 值的位置,您可以在每个索引操作之前添加 assert

local config={}

config.mcast_mac = "00:0a:cd:16:da:f1"

assert(rpc, 'rpc is NULL')

function rpc:epm()
  local pkt = CreateFromPath("ethernet/ip/udp/dcerpc/epm")
  --[[data is put here]]
  SendAndWait(pkt, function(res)
    assert(res, 'res is NULL')
    local epm = res.get_layer("epm")
    --[[data is put here--]]
    assert(epm, 'epm is NULL')
    local uuid = epm.EntryHandleUUID
    assert(uuid, 'epm.EntryHandleUUID is NULL')
    handle = uuid.to_string()
    print("EntryHandleUUID:",handle)
  end, 2000)
  return handle
end