• Advertisement
Sign in to follow this  

Why does this error?

This topic is 2851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this code:
static int __index(lua_State* L) {
	int *Ptr = (int*)lua_topointer(L, -2);
	const char *ind = lua_tostring(L, -1);
	Triangle O = GetPointerObject(Ptr);
	if (ind == "Name") { // This line is what I think errors
		lua_pushstring(L, O.Name.c_str());
	}
	else {
		lua_pushnil(L);
	}
	return 1;
}
And when I run the program in debug I get an error like this: invalid null pointer

Share this post


Link to post
Share on other sites
Advertisement
if(ind == "Name") compares pointers, not "strings." You are almost certainly going to take the false branch every time, because it's not doing what you want it to do.

There are several places you could be dereferencing a null pointer, but it's impossible to say without more information. Step through the code in your debugger.

Share this post


Link to post
Share on other sites
Well I think you have to use string operator there not directly string there. The another thing is that you have not mention that which error message you are getting. If you got the error in that line than it should be proper to use string operator there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement