Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:06:49+00:00 2026-06-18T06:06:49+00:00

This has been driving me nuts for over a week. Below are two snippets

  • 0

This has been driving me nuts for over a week. Below are two snippets of Lua code from a robot player in the game Bitfighter (written in C++, using a variant of LuaWrapper for binding).

When I first start the Lua script, both work exactly as expected. But after some minutes of intense object creation and destruction, variant 2 stops working, and gives me the following error:

robot.lua:253: attempt to call missing or unknown method 'getEnergy' (a nil value)

To my eyes these should function identically. Who can explain the difference?

Notes: target is a (heavy) userdata representing a C++ object. getEnergy and getHealth are properly registered C++ functions. I can reproduce this differing behavior easily. This is Lua 5.1, using the luavec mod.

Variant 1 – always works

local mt = getmetatable(target)
local pow = mt.getEnergy(target) + mt.getHealth(target)

Variant 2 – starts failing after script has been running for an arbitrary amount of time

 local pow = target:getEnergy() + target:getHealth()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:06:51+00:00Added an answer on June 18, 2026 at 6:06 am

    To track what happens when it stops working you can wrap the call in pcall and explore what happened with the target value:

    local ok, res = pcall(function() return target:getEnergy() + target:getHealth() end)
    if not ok then
      local s = "Invalid target value: "..tostring(target).." "..type(target).."\n"
      for k, v in pairs(target) do s = s.."target "..tostring(k).." "..tostring(v).."\n" end
      for k, v in pairs(getmetatable(target)) do s = s.."meta "..tostring(k).." "..tostring(v).."\n" end
      -- add anything else that helps you figure out what happened to target
      error(res..s)
    end
    local pow = res
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been driving me nuts for a week now. I have a class
This has been driving me nuts for the past hour. I have two computers,
This has been driving me nuts. I keep getting the following exception System.InvalidOperationException: The
This has been driving me nuts. I hope it's not been asked before but
This has been driving me nuts all day. I've seen this problem crop up
This has been driving me nuts all day. I have a weird bug that
This has been driving me nuts, I'm posting here after a lot of looking
This has been driving me nuts for a few days. I am desperate for
This has been driving me absolutely nuts. I have a substitute function like this:
This one has been driving me nuts for a few days now and I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.