0

Alright guys, my first time posting here (after many years of reading). I'm pretty new to LUA, and I agree that it's incredibly useful and simple, however I still have a hard time for some reason.

Heads up, I'm basically reinventing the wheel here, but I want to make it as easy as possible for testers to create debuggers for a simulation engine I work with. I could easily just let them do it the way that exists, but at this point, it's personal. I need to understand what the issue is with my logic.

The existing method for creating a debugger in the engine would be something like:

print_message_to_user(string.format("Engine RPM: %d", sensor_data:getEngineRPM()))

However I'm trying to create a function, debugger(), which shortens and simplifies the process:

function debugger(helptext, sensor)
    print_message_to_user(string.format("%s: %d", helptext, sensor_data:..sensor..()))
end

Which is then called like:

debugger("Engine RPM", getEngineLeftRPM)

...and of course doesn't work. I'm sure it has everything to do with the way I'm trying to concatenate the supplied handle with symbology to hopefully call the actual function.

1 Answer 1

3
function debugger(helptext, sensor)
    print_message_to_user(
       string.format("%s: %d", helptext, sensor_data[sensor](sensor_data))
    )
end

debugger("Engine RPM", "getEngineLeftRPM")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.