lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all,

 

I’m writing some lua script for some game software which supplies me a userdata object (or lightuserdata -> I’m not responsible for the code, am not really proficient in C++ and only hazily aware of the difference between lightuserdata and userdata, should this be relevant). I wish to write a wrapper for this object in lua where the wrapper object inherits from the game object. I want to be able to override certain functions on the game object with the wrapper but let other calls that I don’t wish to override pass through:-

 

 

game = game_class:new()

 

game_wrapper = {}

game_wrapper_mt = {__index = game}

 

function game_wrapper:new()

                local retval = {}

                setmetatable(retval, game_wrapper_mt)

                return retval

end

 

my_game = game_wrapper:new()

 

my_game:out("This text should appear in the debug console like as if I’d called game:out()!")

 

 

 

However the above script snippet doesn’t work, throwing the following error:-

 

LUA script error:[string "Test_Libs_Start.lua"]:44: calling 'out' on bad self (game_class expected, got table)

 

 

 

The problem seems to happen when lua resolves the syntactic sugar of my_game:out(string) into my_game.out(my_game, string). Once it’s worked everything out Lua seems to be seeing the last line as:-

 

game:out(my_game, "This text should appear in the debug console like as if I’d called game:out()!")

 

 

If I use the line below it works, but the call is ugly:-

 

my_game.out(game, "This text should appear in the debug console like as if I’d called game:out()!")

 

 

 

I suspect that what I’m trying to do is either impossible or something to do with the setup of the object supplied by the game code, which I can get changed, but I’m out of my depth with C++ and would appreciate any insights.

 

Regards,

 

Stephen

 

 

 




This email is sent by The Creative Assembly Limited company No. 03425917, registered in England & Wales registered office 27 Great West Road, Middlesex, TW8 9BW, England. The contents of this e-mail and any attachments are confidential to the intended recipient and may also be legally privileged. Unless you are the named addressee (or authorised to receive for the addressee) of this email you may not copy, disclose or distribute it to anyone else. If you have received this email in error, please notify us immediately by e-mail on postmaster@creative-assembly.co.uk and then delete the email and any copies. The Creative Assembly Limited have made all reasonable efforts to ensure that this e-mail and any attached documents or software are free from software viruses, but it is the recipient's responsibility to confirm this.
This email is sent by The Creative Assembly Limited company No. 03425917, registered in England & Wales registered office 27 Great West Road, Middlesex, TW8 9BW, England. The contents of this e-mail and any attachments are confidential to the intended recipient and may also be legally privileged. Unless you are the named addressee (or authorised to receive for the addressee) of this email you may not copy, disclose or distribute it to anyone else. If you have received this email in error, please notify us immediately by e-mail on postmaster@creative-assembly.co.uk and then delete the email and any copies. The Creative Assembly Limited have made all reasonable efforts to ensure that this e-mail and any attached documents or software are free from software viruses, but it is the recipient's responsibility to confirm this.