• Strange error when working with C++ Module
    2 replies, posted
Well to start, here's the error: [code] Error - no MetaName string type for userdata (AGH!) [/code] I have a userdata object is essentially a wrapper around C++'s fstream. I have everything set up all well and good but whenever I call a method of the userdata, the game crashes with this result. Note: the metatable is set up properly, however I don't exactly know how references work. [url=https://github.com/matteisan/proio]This is the code[/url]. I aimed for it to be self-explanatory, but if I need to elaborate on anything, I can do so. Thanks for any help, in advance. [editline]15th July 2014[/editline] Update: I found where the error originates. [url=https://github.com/matteisan/proio/blob/master/src/lua_file.cpp]lua_file.cpp[/url] [code] proio::File* L_GetFile( lua_State *state, int inx ) { GarrysMod::Lua::UserData *ud = ( GarrysMod::Lua::UserData * ) LUA->GetUserdata( inx ); return ( proio::File * ) ud->data; } [/code] For some reason, ud is becoming NULL. I do not know why, as when it is pushed onto the stack it is fine.
First off, you should check if the provided index contains a valid useradata using LUA->CheckType(). Can you please post the lua code you get that error from?
[code] require'proio' local f = File( 'test.txt' ) -- Whitelisted f.Close() [/code] Any member function to File causes this error. I will try the CheckType right now to see if it makes a difference. [editline]15th July 2014[/editline] So it looks like you were right with the CheckType. It appears I am mistaken with the metamethods, I had thought it had the same semantics as Lua. For instance: Lua [code] File:Write( content ) = File.Write( File, content ) [/code] So in C++, does the File not get passed as the first argument? How does one access 'self' ? [editline]15th July 2014[/editline] Oh hell, this whole time I was doing f.Close() not f:Close(). I'm a new kind of idiot. Thanks.
Sorry, you need to Log In to post a reply to this thread.