Can Lua create a SDL_Surface?

Recommended Posts

Exactly what the title says. I don't know how it would be done though, since Lua's variables are non-typed.

Share on other sites
That's not really a problem - if it was, then you wouldn't really be able to use any library with Lua. What happens instead is that you just get back an object that you can treat as an SDL_Surface. It doesn't need to have a specific type as such. Typically in Lua this might be a table containing methods that apply to SDL_Surfaces, plus a Userdata item containing a pointer to the actual surface itself.

http://lua-users.org/wiki/LuaModuleLuaSdl

Share on other sites
Ok, thanks. That cleared a lot up.

Share on other sites
One slight problem: since Lua can't recognize a SDL_Surface by default, I tried this:
int x;	int y;	SDL_Surface *source = NULL;	SDL_Surface *dest = NULL;	if (lua_isnumber(LuaVM, 1))	{		x = lua_tointeger(LuaVM, 1);	}	if (lua_isnumber(LuaVM, 2))	{		y = lua_tointeger(LuaVM, 2);	}	if (lua_islightuserdata(LuaVM, 3))	{		source = lua_touserdata(LuaVM, 3);	}	if (lua_islightuserdata(LuaVM, 4))	{		dest = lua_touserdata(LuaVM, 4);	}

But when I go to compile it, it gives me:
error C2440: '=' : cannot convert from 'void *' to 'struct SDL_Surface *'        Conversion from 'void*' to pointer to non-'void' requires an explicit cast

Is there an easy way to fix this or am I doing something horribly wrong?

Share on other sites
The error message tells it all. The compiler warns you that it cannot cast/convert the pointer type and wants you to explicitely place that cast:

source = (SDL_Surface*)lua_touserdata( LuaVM, 3 );

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• Forum Statistics

• Total Topics
628301
• Total Posts
2981913

• 10
• 11
• 11
• 10
• 10