2

I am trying to mod a Lua game (CtGW). There is a function, engine:GetSavegames, which returns an array of strings, and I cannot access. I need to modify the returned results. I tried the following, but recieved a "function arguments expected near 'engine'" error.

getsaves = engine:GetSavegames
engine:GetSavegames = function()
 return getsaves()
end
1
  • 1
    One thing you could try is engine.GetSavegames = ..., that would fix the syntax. Whether this will actually work and do what you want depends on how the rest of the stuff is coded. Commented Nov 12, 2015 at 4:13

1 Answer 1

3

engine:GetSavegames is only valid syntax for method invocation and not for assignments. As @ChrisBeck wrote in the comment, you need to use engine.GetSavegame, but you also need to pass any parameters you can get as those will include the actual object.

Something like this may work:

local getsaves = engine.GetSavegames
engine.GetSavegames = function(...)
  return getsaves(...)
end

This operation is usually called monkeypatching.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, this worked on the Lua demo page. But I don't think there are any parameters possible.
If it's called as engine:GetSavegames, there is going to be at least one parameter as this is equivalent to engine.getSavegames(engine), so the code needs to account for that.
Thanks again, I did need to add that, and have it working now.

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.