Updated LÖVE source to revision cff5bc8604bd

This commit is contained in:
Martin Felis
2015-12-09 22:19:41 +01:00
parent 8f5ee4a05e
commit 66685a2ade
248 changed files with 11591 additions and 9219 deletions
+1
View File
@@ -53,6 +53,7 @@ public:
M_TIMER,
M_TOUCH,
M_WINDOW,
M_VIDEO,
M_MAX_ENUM
};
+10
View File
@@ -117,6 +117,16 @@ public:
return object;
}
operator bool() const
{
return object != nullptr;
}
operator T*() const
{
return object;
}
void set(T *obj)
{
if (obj) obj->retain();
+64
View File
@@ -0,0 +1,64 @@
/**
* Copyright (c) 2006-2015 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_STREAM_H
#define LOVE_STREAM_H
// LOVE
#include <stddef.h>
#include "Object.h"
namespace love
{
class Stream : public Object
{
public:
virtual ~Stream() {}
// getData and getSize are assumed to talk about
// the buffer
/**
* A callback, gets called when some Stream consumer exhausts the data
**/
virtual void fillBackBuffer() {}
/**
* Get the front buffer, Streams are supposed to be (at least) double-buffered
**/
virtual const void *getFrontBuffer() const = 0;
/**
* Get the size of any (and in particular the front) buffer
**/
virtual size_t getSize() const = 0;
/**
* Swap buffers. Returns true if there is new data in the front buffer,
* false otherwise.
* NOTE: If there is no back buffer ready, this call must be ignored
**/
virtual bool swapBuffers() = 0;
}; // Stream
} // love
#endif // LOVE_STREAM_H
+3 -5
View File
@@ -24,8 +24,6 @@
namespace love
{
extern StringMap<Type, TYPE_MAX_ENUM> types;
static love::Type extractudatatype(lua_State *L, int idx)
{
Type t = INVALID_ID;
@@ -36,7 +34,7 @@ static love::Type extractudatatype(lua_State *L, int idx)
lua_pushvalue(L, idx);
int result = lua_pcall(L, 1, 1, 0);
if (result == 0)
types.find(lua_tostring(L, -1), t);
getTypeName(lua_tostring(L, -1), t);
if (result == 0 || result == LUA_ERRRUN)
lua_pop(L, 1);
return t;
@@ -165,7 +163,7 @@ Variant *Variant::fromLua(lua_State *L, int n, bool allowTables)
if (allowTables)
{
bool success = true;
std::vector<std::pair<Variant*, Variant*> > *table = new std::vector<std::pair<Variant*, Variant*> >();
std::vector<std::pair<Variant*, Variant*>> *table = new std::vector<std::pair<Variant*, Variant*>>();
lua_pushnil(L);
while (lua_next(L, n))
{
@@ -230,7 +228,7 @@ void Variant::toLua(lua_State *L)
// I can do (at the moment).
break;
case TABLE:
lua_newtable(L);
lua_createtable(L, 0, (int) data.table->size());
for (size_t i = 0; i < data.table->size(); ++i)
{
std::pair<Variant*, Variant*> &kv = data.table->at(i);
+1 -1
View File
@@ -71,7 +71,7 @@ public:
size_t len;
} string;
void *userdata;
std::vector<std::pair<Variant*, Variant*> > *table;
std::vector<std::pair<Variant*, Variant*>> *table;
} data;
private:
+2
View File
@@ -141,6 +141,8 @@
# define LOVE_ENABLE_TOUCH
# define LOVE_ENABLE_TOUCH_SDL
# define LOVE_ENABLE_UTF8
# define LOVE_ENABLE_VIDEO
# define LOVE_ENABLE_VIDEO_THEORA
# define LOVE_ENABLE_WINDOW
# define LOVE_ENABLE_WINDOW_SDL
# define LOVE_ENABLE_WUFF
+23 -15
View File
@@ -216,6 +216,8 @@ int luax_require(lua_State *L, const char *name)
int luax_register_module(lua_State *L, const WrappedModule &m)
{
love::addTypeName(m.type, m.name);
// Put a reference to the C++ module in Lua.
luax_insistregistry(L, REGISTRY_MODULES);
@@ -270,12 +272,9 @@ int luax_preload(lua_State *L, lua_CFunction f, const char *name)
return 0;
}
int luax_register_type(lua_State *L, love::Type type, const luaL_Reg *f, bool pushmetatable)
int luax_register_type(lua_State *L, love::Type type, const char *name, ...)
{
// Verify that this type name has a matching Type ID and type name mapping.
const char *tname = "Invalid";
if (!love::getType(type, tname))
printf("Missing type name entry for type ID %d\n", type);
love::addTypeName(type, name);
// Get the place for storing and re-using instantiated love types.
luax_getregistry(L, REGISTRY_OBJECTS);
@@ -302,7 +301,7 @@ int luax_register_type(lua_State *L, love::Type type, const luaL_Reg *f, bool pu
else
lua_pop(L, 1);
luaL_newmetatable(L, tname);
luaL_newmetatable(L, name);
// m.__index = m
lua_pushvalue(L, -1);
@@ -317,12 +316,12 @@ int luax_register_type(lua_State *L, love::Type type, const luaL_Reg *f, bool pu
lua_setfield(L, -2, "__eq");
// Add tostring function.
lua_pushstring(L, tname);
lua_pushstring(L, name);
lua_pushcclosure(L, w__tostring, 1);
lua_setfield(L, -2, "__tostring");
// Add type
lua_pushstring(L, tname);
lua_pushstring(L, name);
lua_pushcclosure(L, w__type, 1);
lua_setfield(L, -2, "type");
@@ -330,16 +329,25 @@ int luax_register_type(lua_State *L, love::Type type, const luaL_Reg *f, bool pu
lua_pushcfunction(L, w__typeOf);
lua_setfield(L, -2, "typeOf");
if (f != nullptr)
va_list fs;
va_start(fs, name);
for (const luaL_Reg *f = va_arg(fs, const luaL_Reg *); f; f = va_arg(fs, const luaL_Reg *))
luax_setfuncs(L, f);
if (pushmetatable)
return 1; // leave the metatable on the stack.
va_end(fs);
lua_pop(L, 1); // Pops metatable.
return 0;
}
void luax_gettypemetatable(lua_State *L, love::Type type)
{
const char *name = nullptr;
if (getTypeName(type, name))
lua_getfield(L, LUA_REGISTRYINDEX, name);
else
lua_pushnil(L);
}
int luax_table_insert(lua_State *L, int tindex, int vindex, int pos)
{
if (tindex < 0)
@@ -403,7 +411,7 @@ void luax_rawnewtype(lua_State *L, love::Type type, love::Object *object)
u->type = type;
const char *name = "Invalid";
getType(type, name);
getTypeName(type, name);
luaL_newmetatable(L, name);
lua_setmetatable(L, -2);
@@ -670,7 +678,7 @@ extern "C" int luax_typerror(lua_State *L, int narg, const char *tname)
// Non-love userdata might have a type metamethod which doesn't
// describe its type properly, so we only use it for love types.
love::Type t;
if (!love::getType(argtname, t))
if (!love::getTypeName(argtname, t))
argtname = 0;
}
}
@@ -707,7 +715,7 @@ void luax_register(lua_State *L, const char *name, const luaL_Reg *l)
Type luax_type(lua_State *L, int idx)
{
Type t = INVALID_ID;
getType(luaL_checkstring(L, idx), t);
getTypeName(luaL_checkstring(L, idx), t);
return t;
}
+12 -7
View File
@@ -247,10 +247,15 @@ int luax_preload(lua_State *L, lua_CFunction f, const char *name);
/**
* Register a new type.
* @param type The type.
* @param f The list of member functions for the type.
* @param pushmetatable Whether to push the type's metatable to the stack.
* @param name The type's human-readable name
* @param ... The list of lists of member functions for the type. (of type luaL_Reg*)
**/
int luax_register_type(lua_State *L, love::Type type, const luaL_Reg *f = nullptr, bool pushmetatable = false);
int luax_register_type(lua_State *L, love::Type type, const char *name, ...);
/**
* Pushes the metatable of the specified type onto the stack.
**/
void luax_gettypemetatable(lua_State *L, love::Type type);
/**
* Do a table.insert from C
@@ -434,7 +439,7 @@ T *luax_checktype(lua_State *L, int idx, love::Type type)
if (lua_type(L, idx) != LUA_TUSERDATA)
{
const char *name = "Invalid";
getType(type, name);
getTypeName(type, name);
luax_typerror(L, idx, name);
}
@@ -443,7 +448,7 @@ T *luax_checktype(lua_State *L, int idx, love::Type type)
if (!typeFlags[u->type][type])
{
const char *name = "Invalid";
getType(type, name);
getTypeName(type, name);
luax_typerror(L, idx, name);
}
@@ -454,7 +459,7 @@ template <typename T>
T *luax_getmodule(lua_State *L, love::Type type)
{
const char *name = "Invalid";
getType(type, name);
getTypeName(type, name);
luax_insistregistry(L, REGISTRY_MODULES);
lua_getfield(L, -1, name);
@@ -476,7 +481,7 @@ template <typename T>
T *luax_optmodule(lua_State *L, love::Type type)
{
const char *name = "Invalid";
getType(type, name);
getTypeName(type, name);
luax_insistregistry(L, REGISTRY_MODULES);
lua_getfield(L, -1, name);
+14 -90
View File
@@ -34,6 +34,7 @@ static const TypeBits *createTypeFlags()
b[OBJECT_ID] = one << OBJECT_ID;
b[DATA_ID] = (one << DATA_ID) | b[OBJECT_ID];
b[MODULE_ID] = (one << MODULE_ID) | b[OBJECT_ID];
b[STREAM_ID] = (one << STREAM_ID) | b[OBJECT_ID];
// Filesystem.
b[FILESYSTEM_FILE_ID] = (one << FILESYSTEM_FILE_ID) | b[OBJECT_ID];
@@ -55,6 +56,7 @@ static const TypeBits *createTypeFlags()
b[GRAPHICS_SHADER_ID] = (one << GRAPHICS_SHADER_ID) | b[OBJECT_ID];
b[GRAPHICS_MESH_ID] = (one << GRAPHICS_MESH_ID) | b[GRAPHICS_DRAWABLE_ID];
b[GRAPHICS_TEXT_ID] = (one << GRAPHICS_TEXT_ID) | b[GRAPHICS_DRAWABLE_ID];
b[GRAPHICS_VIDEO_ID] = (one << GRAPHICS_VIDEO_ID) | b[GRAPHICS_DRAWABLE_ID];
// Image.
b[IMAGE_IMAGE_DATA_ID] = (one << IMAGE_IMAGE_DATA_ID) | b[DATA_ID];
@@ -105,6 +107,9 @@ static const TypeBits *createTypeFlags()
b[THREAD_THREAD_ID] = (one << THREAD_THREAD_ID) | b[OBJECT_ID];
b[THREAD_CHANNEL_ID] = (one << THREAD_CHANNEL_ID) | b[OBJECT_ID];
// Video
b[VIDEO_VIDEO_STREAM_ID] = (one << VIDEO_VIDEO_STREAM_ID) | b[STREAM_ID];
// Modules.
b[MODULE_FILESYSTEM_ID] = (one << MODULE_FILESYSTEM_ID) | b[MODULE_ID];
b[MODULE_GRAPHICS_ID] = (one << MODULE_GRAPHICS_ID) | b[MODULE_ID];
@@ -116,102 +121,21 @@ static const TypeBits *createTypeFlags()
const TypeBits *typeFlags = createTypeFlags();
StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[] =
static StringMap<Type, TYPE_MAX_ENUM> types(nullptr, 0);
void addTypeName(Type type, const char *name)
{
{"Invalid", INVALID_ID},
const char *n;
if (!types.find(type, n))
types.add(name, type);
}
{"Object", OBJECT_ID},
{"Data", DATA_ID},
{"Module", MODULE_ID},
// Filesystem
{"File", FILESYSTEM_FILE_ID},
{"DroppedFile", FILESYSTEM_DROPPED_FILE_ID},
{"FileData", FILESYSTEM_FILE_DATA_ID},
// Font
{"GlyphData", FONT_GLYPH_DATA_ID},
{"Rasterizer", FONT_RASTERIZER_ID},
// Graphics
{"Drawable", GRAPHICS_DRAWABLE_ID},
{"Texture", GRAPHICS_TEXTURE_ID},
{"Image", GRAPHICS_IMAGE_ID},
{"Quad", GRAPHICS_QUAD_ID},
{"Font", GRAPHICS_FONT_ID},
{"ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_ID},
{"SpriteBatch", GRAPHICS_SPRITE_BATCH_ID},
{"Canvas", GRAPHICS_CANVAS_ID},
{"Shader", GRAPHICS_SHADER_ID},
{"Mesh", GRAPHICS_MESH_ID},
{"Text", GRAPHICS_TEXT_ID},
// Image
{"ImageData", IMAGE_IMAGE_DATA_ID},
{"CompressedImageData", IMAGE_COMPRESSED_IMAGE_DATA_ID},
// Joystick
{"Joystick", JOYSTICK_JOYSTICK_ID},
// Math
{"RandomGenerator", MATH_RANDOM_GENERATOR_ID},
{"BezierCurve", MATH_BEZIER_CURVE_ID},
{"CompressedData", MATH_COMPRESSED_DATA_ID},
// Audio
{"Source", AUDIO_SOURCE_ID},
// Sound
{"SoundData", SOUND_SOUND_DATA_ID},
{"Decoder", SOUND_DECODER_ID},
// Mouse
{"Cursor", MOUSE_CURSOR_ID},
// Physics
{"World", PHYSICS_WORLD_ID},
{"Contact", PHYSICS_CONTACT_ID},
{"Body", PHYSICS_BODY_ID},
{"Fixture", PHYSICS_FIXTURE_ID},
{"Shape", PHYSICS_SHAPE_ID},
{"CircleShape", PHYSICS_CIRCLE_SHAPE_ID},
{"PolygonShape", PHYSICS_POLYGON_SHAPE_ID},
{"EdgeShape", PHYSICS_EDGE_SHAPE_ID},
{"ChainShape", PHYSICS_CHAIN_SHAPE_ID},
{"Joint", PHYSICS_JOINT_ID},
{"MouseJoint", PHYSICS_MOUSE_JOINT_ID},
{"DistanceJoint", PHYSICS_DISTANCE_JOINT_ID},
{"PrismaticJoint", PHYSICS_PRISMATIC_JOINT_ID},
{"RevoluteJoint", PHYSICS_REVOLUTE_JOINT_ID},
{"PulleyJoint", PHYSICS_PULLEY_JOINT_ID},
{"GearJoint", PHYSICS_GEAR_JOINT_ID},
{"FrictionJoint", PHYSICS_FRICTION_JOINT_ID},
{"WeldJoint", PHYSICS_WELD_JOINT_ID},
{"RopeJoint", PHYSICS_ROPE_JOINT_ID},
{"WheelJoint", PHYSICS_WHEEL_JOINT_ID},
{"MotorJoint", PHYSICS_MOTOR_JOINT_ID},
// Thread
{"Thread", THREAD_THREAD_ID},
{"Channel", THREAD_CHANNEL_ID},
// The modules themselves. Only add abstracted modules here.
{"filesystem", MODULE_FILESYSTEM_ID},
{"graphics", MODULE_GRAPHICS_ID},
{"image", MODULE_IMAGE_ID},
{"sound", MODULE_SOUND_ID},
};
StringMap<Type, TYPE_MAX_ENUM> types(typeEntries, sizeof(typeEntries));
static_assert((sizeof(typeEntries) / sizeof(typeEntries[0])) == TYPE_MAX_ENUM, "Type name array size doesn't match the total number of type IDs!");
bool getType(const char *in, love::Type &out)
bool getTypeName(const char *in, love::Type &out)
{
return types.find(in, out);
}
bool getType(love::Type in, const char *&out)
bool getTypeName(love::Type in, const char *&out)
{
return types.find(in, out);
}
+8 -2
View File
@@ -34,6 +34,7 @@ enum Type
OBJECT_ID,
DATA_ID,
MODULE_ID,
STREAM_ID,
// Filesystem.
FILESYSTEM_FILE_ID,
@@ -56,6 +57,7 @@ enum Type
GRAPHICS_SHADER_ID,
GRAPHICS_MESH_ID,
GRAPHICS_TEXT_ID,
GRAPHICS_VIDEO_ID,
// Image
IMAGE_IMAGE_DATA_ID,
@@ -106,6 +108,9 @@ enum Type
THREAD_THREAD_ID,
THREAD_CHANNEL_ID,
// Video
VIDEO_VIDEO_STREAM_ID,
// The modules themselves. Only add abstracted modules here.
MODULE_FILESYSTEM_ID,
MODULE_GRAPHICS_ID,
@@ -123,8 +128,9 @@ typedef std::bitset<TYPE_MAX_ENUM> TypeBits;
**/
extern const TypeBits *typeFlags;
bool getType(const char *in, Type &out);
bool getType(Type in, const char *&out);
void addTypeName(Type type, const char *name);
bool getTypeName(const char *in, Type &out);
bool getTypeName(Type in, const char *&out);
} // love
+1 -1
View File
@@ -31,7 +31,7 @@ static const int VERSION_MINOR = 10;
static const int VERSION_REV = 0;
static const char *VERSION = LOVE_VERSION_STRING;
static const char *VERSION_COMPATIBILITY[] = { VERSION, 0 };
static const char *VERSION_CODENAME = "";
static const char *VERSION_CODENAME = "Super Toast";
} // love
+1 -1
View File
@@ -59,7 +59,7 @@ const luaL_Reg w_Data_functions[] =
int w_Data_open(lua_State *L)
{
luax_register_type(L, DATA_ID, w_Data_functions);
luax_register_type(L, DATA_ID, "Data", w_Data_functions, nullptr);
return 0;
}
+1 -3
View File
@@ -29,10 +29,8 @@ namespace love
{
Data *luax_checkdata(lua_State *L, int idx);
int w_Data_getString(lua_State *L);
int w_Data_getPointer(lua_State *L);
int w_Data_getSize(lua_State *L);
int w_Data_open(lua_State *L);
extern const luaL_Reg w_Data_functions[];
} // love