mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
Modules now reside in Lua and are treated (almost) like normal objects.
Also added a way of getting a pointer to abstract module instances internally.
This commit is contained in:
@@ -266,9 +266,15 @@ namespace audio
|
||||
if(instance == 0)
|
||||
return luaL_error(L, "Could not open any audio module.");
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
return luax_register_module(L, functions, types, 0, "audio");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "audio";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
w.constants = 0;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // audio
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace sdl
|
||||
};
|
||||
|
||||
// List of constants.
|
||||
static const LuaConstant constants[] = {
|
||||
static const Constant constants[] = {
|
||||
{ "event_keypressed", Event::EVENT_KEYDOWN },
|
||||
{ "event_keyreleased", Event::EVENT_KEYUP },
|
||||
{ "event_mousepressed", Event::EVENT_MOUSEBUTTONDOWN },
|
||||
@@ -97,9 +97,15 @@ namespace sdl
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
return luax_register_module(L, functions, 0, constants, "event");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "event";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = 0;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // sdl
|
||||
|
||||
@@ -252,7 +252,7 @@ namespace physfs
|
||||
};
|
||||
|
||||
// List of constants.
|
||||
static const LuaConstant constants[] = {
|
||||
static const Constant constants[] = {
|
||||
{ "file_closed", File::CLOSED },
|
||||
{ "file_read", File::READ },
|
||||
{ "file_write", File::WRITE },
|
||||
@@ -275,9 +275,15 @@ namespace physfs
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "filesystem";
|
||||
w.flags = MODULE_FILESYSTEM_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, functions, types, constants, "filesystem");
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // physfs
|
||||
|
||||
@@ -80,9 +80,15 @@ namespace freetype
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
return luax_register_module(L, functions, types, 0, "font");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "font";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
w.constants = 0;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // freetype
|
||||
|
||||
@@ -22,10 +22,6 @@
|
||||
|
||||
// LOVE
|
||||
#include <common/config.h>
|
||||
#include <image/devil/Image.h>
|
||||
|
||||
// IL
|
||||
#include <IL/ilu.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -1177,70 +1173,15 @@ namespace opengl
|
||||
return 0;
|
||||
}
|
||||
|
||||
love::image::ImageData * Graphics::newScreenshot(lua_State * L)
|
||||
love::image::ImageData * Graphics::newScreenshot(love::image::Image * image)
|
||||
{
|
||||
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
|
||||
love::image::devil::Image * i = new love::image::devil::Image();
|
||||
love::image::ImageData * img = i->newImageData(w, h);
|
||||
|
||||
GLubyte * pixels = new GLubyte[4*w*h];
|
||||
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
try {
|
||||
img = i->newImageData(w, h, pixels);
|
||||
} catch (Exception & e) {
|
||||
luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
// the screenshot is upside down, let's fix this
|
||||
iluFlipImage();
|
||||
|
||||
delete [] pixels;
|
||||
|
||||
return img;
|
||||
|
||||
// TODO: update this.
|
||||
/*
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
|
||||
// Declare some storage.
|
||||
GLubyte * pixels = new GLubyte[3*w*h];
|
||||
GLubyte * screenshot = new GLubyte[3*w*h];
|
||||
ILuint image;
|
||||
|
||||
// Read the pixels on the screen.
|
||||
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
ilGenImages(1, &image);
|
||||
ilBindImage(image);
|
||||
ilTexImage(w, h, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, (ILvoid*)pixels);
|
||||
|
||||
delete [] pixels;
|
||||
|
||||
// Create the image.
|
||||
ilSaveL(IL_BMP, screenshot, 3*w*h);
|
||||
|
||||
bool success = true;
|
||||
|
||||
if(file->open())
|
||||
{
|
||||
if(!file->write((const char *)screenshot, 3*w*h))
|
||||
success = false;
|
||||
file->close();
|
||||
}
|
||||
else
|
||||
success = false;
|
||||
|
||||
delete [] screenshot;
|
||||
ilDeleteImages(1, &image);
|
||||
*/
|
||||
|
||||
return false;
|
||||
return image->newImageData(w, h, (void*)pixels);
|
||||
}
|
||||
|
||||
void Graphics::push()
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
// LOVE
|
||||
#include <graphics/Graphics.h>
|
||||
|
||||
#include <image/Image.h>
|
||||
#include <image/ImageData.h>
|
||||
|
||||
#include "Image.h"
|
||||
@@ -518,7 +519,7 @@ namespace opengl
|
||||
* Creates a screenshot of the view and saves it to the default folder.
|
||||
* @param file The file to write the screenshot to.
|
||||
**/
|
||||
love::image::ImageData * newScreenshot(lua_State * L);
|
||||
love::image::ImageData * newScreenshot(love::image::Image * image);
|
||||
|
||||
void push();
|
||||
void pop();
|
||||
|
||||
@@ -479,7 +479,8 @@ namespace opengl
|
||||
|
||||
int w_newScreenshot(lua_State * L)
|
||||
{
|
||||
love::image::ImageData * i = instance->newScreenshot(L);
|
||||
love::image::Image * image = luax_getmodule<love::image::Image>(L, "image", MODULE_IMAGE_T);
|
||||
love::image::ImageData * i = instance->newScreenshot(image);
|
||||
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)i);
|
||||
return 1;
|
||||
}
|
||||
@@ -795,7 +796,7 @@ namespace opengl
|
||||
};
|
||||
|
||||
// List of constants.
|
||||
static const LuaConstant constants[] = {
|
||||
static const Constant constants[] = {
|
||||
|
||||
{ "align_left", Graphics::ALIGN_LEFT },
|
||||
{ "align_right", Graphics::ALIGN_RIGHT },
|
||||
@@ -860,8 +861,15 @@ namespace opengl
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
luax_register_module(L, functions, types, constants, "graphics");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "graphics";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
w.constants = constants;
|
||||
|
||||
luax_register_module(L, w);
|
||||
|
||||
# include <scripts/graphics.lua.h>
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace devil
|
||||
// Bind the image.
|
||||
ilBindImage(image);
|
||||
// Try to load the data.
|
||||
bool success = ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data);
|
||||
bool success = (ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data) == IL_TRUE);
|
||||
int err = ilGetError();
|
||||
if (err != IL_NO_ERROR){
|
||||
switch (err) {
|
||||
|
||||
@@ -92,9 +92,15 @@ namespace image
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
return luax_register_module(L, functions, types, 0, "image");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "image";
|
||||
w.flags = MODULE_IMAGE_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
w.constants = 0;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // image
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace sdl
|
||||
};
|
||||
|
||||
// List of constants.
|
||||
static const LuaConstant constants[] = {
|
||||
static const Constant constants[] = {
|
||||
{ "joystick_axis_horizontal", Joystick::JOYSTICK_AXIS_HORIZONTAL },
|
||||
{ "joystick_axis_vertical", Joystick::JOYSTICK_AXIS_VERITCAL },
|
||||
|
||||
@@ -176,9 +176,16 @@ namespace sdl
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
return luax_register_module(L, functions, 0, constants, "joystick");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "joystick";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = 0;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // sdl
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace sdl
|
||||
};
|
||||
|
||||
// List of constants.
|
||||
static const LuaConstant constants[] = {
|
||||
static const Constant constants[] = {
|
||||
{ "key_unknown", 0 },
|
||||
{ "key_first", 0 },
|
||||
{ "key_backspace", 8 },
|
||||
@@ -232,9 +232,15 @@ namespace sdl
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
return luax_register_module(L, functions, 0, constants, "keyboard");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "keyboard";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = 0;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // sdl
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace sdl
|
||||
};
|
||||
|
||||
// List of constants.
|
||||
static const LuaConstant constants[] = {
|
||||
static const Constant constants[] = {
|
||||
{ "mouse_left", Mouse::MOUSE_LEFT },
|
||||
{ "mouse_middle", Mouse::MOUSE_MIDDLE },
|
||||
{ "mouse_right", Mouse::MOUSE_RIGHT },
|
||||
@@ -129,9 +129,15 @@ namespace sdl
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
return luax_register_module(L, functions, 0, constants, "mouse");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "mouse";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = 0;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // sdl
|
||||
|
||||
@@ -137,9 +137,15 @@ namespace tcc
|
||||
|
||||
luax_register_searcher(L, searcher);
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
return luax_register_module(L, functions, 0, 0, "native");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "native";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = 0;
|
||||
w.constants = 0;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // tcc
|
||||
|
||||
@@ -237,7 +237,7 @@ namespace box2d
|
||||
};
|
||||
|
||||
// List of constants.
|
||||
static const LuaConstant constants[] = {
|
||||
static const Constant constants[] = {
|
||||
{ "shape_circle", Shape::SHAPE_CIRCLE },
|
||||
{ "shape_polygon", Shape::SHAPE_POLYGON },
|
||||
|
||||
@@ -264,7 +264,15 @@ namespace box2d
|
||||
}
|
||||
}
|
||||
|
||||
return luax_register_module(L, functions, types, constants, "physics");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "physics";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace posix
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static const LuaConstant constants[] = {
|
||||
static const Constant constants[] = {
|
||||
{ "signal_abrt", SIGABRT },
|
||||
{ "signal_fpe", SIGFPE },
|
||||
{ "signal_ill", SIGILL },
|
||||
@@ -86,9 +86,16 @@ namespace posix
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "signal";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = 0;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, functions, 0, constants, "signal");
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // posix
|
||||
|
||||
@@ -128,9 +128,16 @@ namespace sound
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
return luax_register_module(L, functions, types, 0, "sound");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "sound";
|
||||
w.flags = MODULE_SOUND_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
w.constants = 0;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // sound
|
||||
|
||||
@@ -85,9 +85,15 @@ namespace sdl
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, instance);
|
||||
|
||||
return luax_register_module(L, functions, 0, 0, "timer");
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "timer";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = 0;
|
||||
w.constants = 0;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // sdl
|
||||
|
||||
Reference in New Issue
Block a user