Jump to content
  • Advertisement
Sign in to follow this  
orcfan32

Can Lua create a SDL_Surface?

This topic is 4399 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

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

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 );

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!