Initial Mercurial commit.

This commit is contained in:
rude
2009-07-26 15:46:49 +02:00
commit dcb3dfd83d
417 changed files with 124060 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
/**
* Copyright (c) 2006-2009 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_DATA_H
#define LOVE_DATA_H
// LOVE
#include "Object.h"
namespace love
{
class Data : public Object
{
public:
virtual ~Data() {};
/**
* Gets a pointer to the data.
**/
virtual void * getData() const = 0 ;
/**
* Gets the size of the data buffer.
**/
virtual int getSize() const = 0;
}; // Data
} // love
#endif // LOVE_DATA_H
+38
View File
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2006-2009 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.
**/
#include "Exception.h"
namespace love
{
Exception::Exception(const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
vsnprintf(buffer, BUFFER_SIZE, fmt, args);
va_end(args);
}
const char * Exception::what() const throw()
{
return (const char *)buffer;
}
}
+44
View File
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2006-2009 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_EXCEPTION_H
#define LOVE_EXCEPTION_H
#include <exception>
#include <string>
#include <cstdarg>
#include <cstdio>
namespace love
{
class Exception : public std::exception
{
private:
static const int BUFFER_SIZE = 256;
char buffer[BUFFER_SIZE];
public:
Exception(const char * fmt, ...);
virtual const char * what() const throw();
};
}
#endif // LOVE_EXCEPTION_H
+176
View File
@@ -0,0 +1,176 @@
/**
* Copyright (c) 2006-2009 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.
**/
#include "Matrix.h"
// STD
#include <cstring>
#include <cmath>
// LOVE
#include "Vector.h"
namespace love
{
// | e0 e4 e8 e12 |
// | e1 e5 e9 e13 |
// | e2 e6 e10 e14 |
// | e3 e7 e11 e15 |
Matrix::Matrix()
{
setIdentity();
}
Matrix::~Matrix()
{
}
// | e0 e4 e8 e12 |
// | e1 e5 e9 e13 |
// | e2 e6 e10 e14 |
// | e3 e7 e11 e15 |
// | e0 e4 e8 e12 |
// | e1 e5 e9 e13 |
// | e2 e6 e10 e14 |
// | e3 e7 e11 e15 |
Matrix Matrix::operator * (const Matrix & m) const
{
Matrix t;
t.e[0] = (e[0]*m.e[0]) + (e[4]*m.e[1]) + (e[8]*m.e[2]) + (e[12]*m.e[3]);
t.e[4] = (e[0]*m.e[4]) + (e[4]*m.e[5]) + (e[8]*m.e[6]) + (e[12]*m.e[7]);
t.e[8] = (e[0]*m.e[8]) + (e[4]*m.e[9]) + (e[8]*m.e[10]) + (e[12]*m.e[11]);
t.e[12] = (e[0]*m.e[12]) + (e[4]*m.e[13]) + (e[8]*m.e[14]) + (e[12]*m.e[15]);
t.e[1] = (e[1]*m.e[0]) + (e[5]*m.e[1]) + (e[9]*m.e[2]) + (e[13]*m.e[3]);
t.e[5] = (e[1]*m.e[4]) + (e[5]*m.e[5]) + (e[9]*m.e[6]) + (e[13]*m.e[7]);
t.e[9] = (e[1]*m.e[8]) + (e[5]*m.e[9]) + (e[9]*m.e[10]) + (e[13]*m.e[11]);
t.e[13] = (e[1]*m.e[12]) + (e[5]*m.e[13]) + (e[9]*m.e[14]) + (e[13]*m.e[15]);
t.e[2] = (e[2]*m.e[0]) + (e[6]*m.e[1]) + (e[10]*m.e[2]) + (e[14]*m.e[3]);
t.e[6] = (e[2]*m.e[4]) + (e[6]*m.e[5]) + (e[10]*m.e[6]) + (e[14]*m.e[7]);
t.e[10] = (e[2]*m.e[8]) + (e[6]*m.e[9]) + (e[10]*m.e[10]) + (e[14]*m.e[11]);
t.e[14] = (e[2]*m.e[12]) + (e[6]*m.e[13]) + (e[10]*m.e[14]) + (e[14]*m.e[15]);
t.e[3] = (e[3]*m.e[0]) + (e[7]*m.e[1]) + (e[11]*m.e[2]) + (e[15]*m.e[3]);
t.e[7] = (e[3]*m.e[4]) + (e[7]*m.e[5]) + (e[11]*m.e[6]) + (e[15]*m.e[7]);
t.e[11] = (e[3]*m.e[8]) + (e[7]*m.e[9]) + (e[11]*m.e[10]) + (e[15]*m.e[11]);
t.e[15] = (e[3]*m.e[12]) + (e[7]*m.e[13]) + (e[11]*m.e[14]) + (e[15]*m.e[15]);
return t;
}
void Matrix::operator *= (const Matrix & m) const
{
Matrix t = (*this) * m;
memcpy((void*)this->e, (void*)t.e, sizeof(float)*16);
}
const float * Matrix::getElements() const
{
return e;
}
void Matrix::setIdentity()
{
memset(e, 0, sizeof(float)*16);
e[0] = e[5] = e[10] = e[15] = 1;
}
void Matrix::setTranslation(float x, float y)
{
setIdentity();
e[12] = x;
e[13] = y;
}
void Matrix::setRotation(float rad)
{
setIdentity();
float c = cos(rad), s = sin(rad);
e[0] = c; e[4] = -s;
e[1] = s; e[5] = c;
}
void Matrix::setScale(float sx, float sy)
{
setIdentity();
e[0] = sx;
e[5] = sy;
}
void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy)
{
// TODO: This works fine, but should consider speeding this up a little.
setIdentity();
translate(x, y);
rotate(angle);
scale(sx, sy);
translate(-ox, -oy);
}
void Matrix::translate(float x, float y)
{
Matrix t;
t.setTranslation(x, y);
this->operator *=(t);
}
void Matrix::rotate(float rad)
{
Matrix t;
t.setRotation(rad);
this->operator *=(t);
}
void Matrix::scale(float sx, float sy)
{
Matrix t;
t.setScale(sx, sy);
this->operator *=(t);
}
// | x |
// | y |
// | 0 |
// | 1 |
// | e0 e4 e8 e12 |
// | e1 e5 e9 e13 |
// | e2 e6 e10 e14 |
// | e3 e7 e11 e15 |
void Matrix::transform(vertex * dst, const vertex * src, int size)
{
for(int i = 0;i<size;i++)
{
// Store in temp variables in case src = dst
float x = (e[0]*src[i].x) + (e[4]*src[i].y) + (0) + (e[12]);
float y = (e[1]*src[i].x) + (e[5]*src[i].y) + (0) + (e[13]);
dst[i].x = x;
dst[i].y = y;
}
}
} // love
+96
View File
@@ -0,0 +1,96 @@
/**
* Copyright (c) 2006-2009 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_MATRIX_H
#define LOVE_MATRIX_H
// STD
#include <cmath>
// LOVE
#include "math.h"
namespace love
{
// Forward declarations.
class Vector;
class Matrix
{
friend class Vector;
public:
// | e0 e4 e8 e12 |
// | e1 e5 e9 e13 |
// | e2 e6 e10 e14 |
// | e3 e7 e11 e15 |
float e[16];
/**
* Creates a new identity matrix.
**/
Matrix();
/**
* Destructor.
**/
~Matrix();
Matrix operator * (const Matrix & m) const;
void operator *= (const Matrix & m) const;
const float * getElements() const;
void setIdentity();
void setTranslation(float x, float y);
void setRotation(float rad);
void setScale(float sx, float sy);
/**
* Creates a transformation with a certain position, orientation, scale
* and offset.
*
* @param x The translation along the x-axis.
* @param y The translation along the y-axis.
* @param angle The rotation (rad) around the center with offset (ox,oy).
* @param sx Scale along x-axis.
* @param sy Scale along y-axis.
* @param ox The offset for rotation along the x-axis.
* @param oy The offset for rotation along the y-axis.
**/
void setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy);
void translate(float x, float y);
void rotate(float rad);
void scale(float sx, float sy);
/**
* Transforms an array of vertices.
* @stride Stride in bytes.
**/
void transform(vertex * dst, const vertex * src, int size);
};
} //love
#endif// LOVE_MATRIX_H
+56
View File
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2006-2009 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_MODULE_H
#define LOVE_MODULE_H
// LOVE
#include "runtime.h"
#include "Exception.h"
namespace love
{
/**
* Abstract superclass for all modules.
*
* @author Anders Ruud
**/
class Module
{
public:
/**
* Destructor.
**/
virtual ~Module(){};
/**
* Gets the name of the module. This is used in case of errors
* and other messages.
*
* @return The full name of the module, eg. love.graphics.opengl.
**/
virtual const char * getName() const = 0;
}; // Module
} // love
#endif // LOVE_MODULE_H
+53
View File
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2006-2009 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.
**/
// LOVE
#include "Object.h"
namespace love
{
Object::Object()
: count(1)
{
}
Object::~Object()
{
// PURE VIRUTAL!
}
int Object::getReferenceCount() const
{
return count;
}
void Object::retain()
{
++count;
}
void Object::release()
{
if(--count <= 0)
delete this;
}
} // love
+78
View File
@@ -0,0 +1,78 @@
/**
* Copyright (c) 2006-2009 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_OBJECT_H
#define LOVE_OBJECT_H
namespace love
{
/**
* Superclass for all object that should be able to cross the Lua/C border
* (this pertains to most objects).
*
* This class is an alternative to using smart pointers; it contains retain/release
* methods, and will delete itself with the reference count hits zero. The wrapper
* code assumes that all userdata inherits from this class.
*
* @author Anders Ruud
**/
class Object
{
private:
// The reference count.
int count;
public:
/**
* Constructor. Sets reference count to one.
**/
Object();
/**
* Destructor.
**/
virtual ~Object() = 0;
/**
* Gets the reference count of this Object.
* @returns The reference count.
**/
int getReferenceCount() const;
/**
* Retains the Object, i.e. increases the
* reference count by one.
**/
void retain();
/**
* Releases one reference to the Object, i.e. decrements the
* reference count by one, and potentially deletes the Object
* if there are no more references.
**/
void release();
}; // Object
} // love
#endif // LOVE_OBJECT_H
+70
View File
@@ -0,0 +1,70 @@
/**
* Copyright (c) 2006-2009 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.
**/
#include "Reference.h"
namespace love
{
Reference::Reference()
: L(0), idx(LUA_REFNIL)
{
}
Reference::Reference(lua_State * L)
: L(0), idx(LUA_REFNIL)
{
ref(L);
}
Reference::~Reference()
{
unref();
}
void Reference::ref(lua_State * L)
{
unref(); // Just to be safe.
this->L = L;
idx = luaL_ref(L, LUA_GLOBALSINDEX);
}
void Reference::unref()
{
if(idx != LUA_REFNIL)
{
luaL_unref(L, LUA_GLOBALSINDEX, idx);
idx = LUA_REFNIL;
}
}
void Reference::push()
{
if(idx != LUA_REFNIL)
lua_rawgeti(L, LUA_GLOBALSINDEX, idx);
else
lua_pushnil(L);
}
lua_State * Reference::getL()
{
return L;
}
} // love
+87
View File
@@ -0,0 +1,87 @@
/**
* Copyright (c) 2006-2009 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_REFERENCE_H
#define LOVE_REFERENCE_H
// LOVE
#include "runtime.h"
namespace love
{
/**
* This class wraps the reference functionality built into
* Lua, which allows C++ code to refer to Lua variables.
**/
class Reference
{
private:
// The Lua state in which the reference resides.
lua_State * L;
// Index to the Lua reference.
int idx;
public:
/**
* Creates the reference object, but does not create
* the actual reference.
**/
Reference();
/**
* Creates the object and a reference to the value
* on the top of the stack.
**/
Reference(lua_State * L);
/**
* Deletes the reference, if any.
**/
virtual ~Reference();
/**
* Creates a reference to the value on the
* top of the stack.
**/
void ref(lua_State * L);
/**
* Unrefs the reference, if any.
**/
void unref();
/**
* Pushes the referred value onto the stack.
**/
void push();
/**
* Gets the Lua state associated with this
* reference.
**/
lua_State * getL();
};
} // love
#endif // LOVE_REFERENCE_H
+26
View File
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2006-2009 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.
**/
#include "Vector.h"
namespace love
{
// Implementation in header.
}
+310
View File
@@ -0,0 +1,310 @@
/**
* Copyright (c) 2006-2009 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_VECTOR_H
#define LOVE_VECTOR_H
// STD
#include <cmath>
// LOVE
#include "Matrix.h"
namespace love
{
/**
* 2D Vector class.
*
* @author Anders Ruud
* @date 2006-05-13
**/
class Vector
{
public:
// The components.
float x, y;
/**
* Creates a new (1,1) Vector.
**/
Vector();
/**
* Creates a new Vector.
* @param x The x position/dimension.
* @param y The y position/dimension.
**/
Vector(float x, float y);
/**
* Gets the length of the Vector.
* @return The length of the Vector.
*
* This method requires sqrt() and should be used
* carefully.
**/
float getLength() const;
/**
* Normalizes the Vector.
* @return The old length of the Vector.
**/
float normalize();
/**
* Gets a normal to the Vector.
* @return A normal to the Vector.
**/
Vector getNormal() const;
/**
* Adds a Vector to this Vector.
* @param v The Vector we want to add to this Vector.
* @return The resulting Vector.
**/
Vector operator + (const Vector & v) const;
/**
* Substracts a Vector to this Vector.
* @param v The Vector we want to subtract to this Vector.
* @return The resulting Vector.
**/
Vector operator - (const Vector & v) const;
/**
* Resizes a Vector by a scalar.
* @param s The scalar with which to resize the Vector.
* @return The resulting Vector.
**/
Vector operator * (float s) const;
/**
* Resizes a Vector by a scalar.
* @param s The scalar with which to resize the Vector.
* @return The resulting Vector.
**/
Vector operator / (float s) const;
/**
* Reverses the Vector.
* @return The reversed Vector.
**/
Vector operator - () const;
/**
* Adds a Vector to this Vector, and also saves changes in the first Vector.
* @param v The Vector we want to add to this Vector.
**/
void operator += (const Vector & v);
/**
* Subtracts a Vector to this Vector, and also saves changes in the first Vector.
* @param v The Vector we want to subtract to this Vector.
**/
void operator -= (const Vector & v);
/**
* Resizes the Vector, and also saves changes in the first Vector.
* @param s The scalar by which we want to resize the Vector.
**/
void operator *= (float s);
/**
* Resizes the Vector, and also saves changes in the first Vector.
* @param s The scalar by which we want to resize the Vector.
**/
void operator /= (float s);
/**
* Calculates the dot product of two Vectors.
* @return The dot product of the two Vectors.
**/
float operator * (const Vector & v) const;
/**
* Calculates the cross product of two Vectors.
* @return The cross product of the two Vectors.
**/
float operator ^ (const Vector & v) const;
bool operator == (const Vector & v) const;
bool operator < (const Vector & v) const;
/**
* Gets the x value of the Vector.
* @return The x value of the Vector.
**/
float getX() const;
/**
* Gets the x value of the Vector.
* @return The x value of the Vector.
**/
float getY() const;
/**
* Sets the x value of the Vector.
* @param The x value of the Vector.
**/
void setX(float x);
/**
* Sets the x value of the Vector.
* @param The x value of the Vector.
**/
void setY(float y);
};
inline float Vector::getLength() const
{
return sqrt(x*x + y*y);
}
inline Vector Vector::getNormal() const
{
return Vector(-y, x);
}
inline float Vector::normalize()
{
float len = getLength();
if(len > 0)
(*this) /= len;
return len;
}
/**
* Inline methods must have body in header.
**/
inline Vector::Vector()
{
x = 1;
y = 1;
}
inline Vector::Vector(float x, float y)
{
this->x = x;
this->y = y;
}
inline Vector Vector::operator + (const Vector & v) const
{
return Vector(x + v.x, y + v.y);
}
inline Vector Vector::operator - (const Vector & v) const
{
return Vector(x - v.getX(), y - v.getY());
}
inline Vector Vector::operator * (float s) const
{
return Vector(x*s, y*s);
}
inline Vector Vector::operator / (float s) const
{
return Vector(x/s, y/s);
}
inline Vector Vector::operator - () const
{
return Vector(-x, -y);
}
inline void Vector::operator += (const Vector & v)
{
x += v.getX();
y += v.getY();
}
inline void Vector::operator -= (const Vector & v)
{
x -= v.getX();
y -= v.getY();
}
inline void Vector::operator *= (float s)
{
x *= s;
y *= s;
}
inline void Vector::operator /= (float s)
{
x /= s;
y /= s;
}
inline float Vector::operator * (const Vector & v) const
{
return x * v.getX() + y * v.getY();
}
inline float Vector::operator ^ (const Vector & v) const
{
return x * v.getY() - y * v.getX();
}
inline bool Vector::operator == (const Vector & v) const
{
return getLength() == v.getLength();
}
inline bool Vector::operator < (const Vector & v) const
{
return getLength() < v.getLength();
}
/**
* Accessor methods
**/
inline float Vector::getX() const
{
return x;
}
inline float Vector::getY() const
{
return y;
}
inline void Vector::setX(float x)
{
this->x = x;
}
inline void Vector::setY(float y)
{
this->y = y;
}
} //love
#endif// LOVE_VECTOR_H
+63
View File
@@ -0,0 +1,63 @@
/**
* Copyright (c) 2006-2009 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_CONFIG_H
#define LOVE_CONFIG_H
// STD
#include <string>
// Platform stuff.
#if defined(WIN32) || defined(_WIN32)
# define LOVE_WINDOWS 1
#endif
#if defined(linux) || defined(__linux) || defined(__linux__)
# define LOVE_LINUX 1
#endif
#if defined(__APPLE__)
# define LOVE_MACOSX 1
#endif
#if defined(macintosh)
# define LOVE_MACOS 1
#endif
// Build.
#define LOVE_BUILD_EXE 1
#define LOVE_BUILD_DLL 0
// Version stuff.
const int LOVE_VERSION = 060;
const int LOVE_VERSION_COMPATIBILITY[] = { 0 };
const std::string LOVE_VERSION_STR = "0.6.0";
const std::string LOVE_VERSION_CODENAME = "Jiggly Juice";
const std::string LOVE_VERSION_FULL_STR = std::string("LOVE ") + LOVE_VERSION_STR + std::string(" (") + LOVE_VERSION_CODENAME + std::string(")");
// DLL-stuff.
#ifdef LOVE_WINDOWS
# ifndef DECLSPEC
# define DECLSPEC __declspec(dllexport)
# endif
#else
# ifndef DECLSPEC
# define DECLSPEC
# endif
#endif
#endif // LOVE_CONFIG_H
+70
View File
@@ -0,0 +1,70 @@
/**
* Copyright (c) 2006-2009 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_MATH_H
#define LOVE_MATH_H
/* Definitions of useful mathematical constants
* M_E - e
* M_LOG2E - log2(e)
* M_LOG10E - log10(e)
* M_LN2 - ln(2)
* M_LN10 - ln(10)
* M_PI - pi
* M_PI_2 - pi/2
* M_PI_4 - pi/4
* M_1_PI - 1/pi
* M_2_PI - 2/pi
* M_2_SQRTPI - 2/sqrt(pi)
* M_SQRT2 - sqrt(2)
* M_SQRT1_2 - 1/sqrt(2)
*/
#define LOVE_M_E 2.71828182845904523536
#define LOVE_M_LOG2E 1.44269504088896340736
#define LOVE_M_LOG10E 0.434294481903251827651
#define LOVE_M_LN2 0.693147180559945309417
#define LOVE_M_LN10 2.30258509299404568402
#define LOVE_M_PI 3.14159265358979323846
#define LOVE_M_PI_2 1.57079632679489661923
#define LOVE_M_PI_4 0.785398163397448309616
#define LOVE_M_1_PI 0.318309886183790671538
#define LOVE_M_2_PI 0.636619772367581343076
#define LOVE_M_2_SQRTPI 1.12837916709551257390
#define LOVE_M_SQRT2 1.41421356237309504880
#define LOVE_M_SQRT1_2 0.707106781186547524401
#define LOVE_M_TORAD (float)(LOVE_M_PI/180.0)
#define LOVE_M_TODEG (float)(180.0/LOVE_M_PI)
#define LOVE_TORAD(x) (float)(x*LOVE_M_TORAD)
#define LOVE_TODEG(x) (float)(x*LOVE_M_TODEG)
namespace love
{
struct vertex
{
unsigned char r, g, b, a;
float x, y;
float s, t;
};
} // love
#endif // LOVE_MATH_H
+278
View File
@@ -0,0 +1,278 @@
/**
* Copyright (c) 2006-2009 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.
**/
#include "runtime.h"
// LOVE
#include "Module.h"
#include "Object.h"
// STD
#include <iostream>
namespace love
{
/**
* Called when an object is collected. The object is released
* once in this function, possibly deleting it.
**/
static int _wrap__gc(lua_State * L)
{
userdata * u = (userdata *)lua_touserdata(L, 1);
Object * t = (Object *)u->data;
t->release();
return 0;
}
/**
* Special garbage collector for Modules.
**/
static int _wrap__Module_gc(lua_State * L)
{
userdata * u = (userdata *)lua_touserdata(L, 1);
Module * t = (Module *)u->data;
delete t;
return 0;
}
void luax_printstack(lua_State * L)
{
for(int i = 1;i<=lua_gettop(L);i++)
{
std::cout << i << " - " << luaL_typename(L, i) << std::endl;
}
}
bool luax_toboolean(lua_State * L, int idx)
{
return (lua_toboolean(L, idx) == 1 ? true : false);
}
void luax_pushboolean(lua_State * L, bool b)
{
lua_pushboolean(L, b ? 1 : 0);
}
bool luax_optboolean(lua_State * L, int idx, bool b)
{
if(lua_isboolean(L, idx) == 1)
return (lua_toboolean(L, idx) == 1 ? true : false);
return b;
}
int luax_assert_argc(lua_State * L, int lower)
{
int argc = lua_gettop(L);
if( argc < lower )
return luaL_error(L, "Incorrect number of arguments. Got [%d], expected at least [%d]", argc, lower);
return 0;
}
int luax_assert_argc(lua_State * L, int lower, int upper)
{
int argc = lua_gettop(L);
if( argc < lower || argc > upper)
return luaL_error(L, "Incorrect number of arguments. Got [%d], expected [%d-%d]", argc, lower, upper);
return 0;
}
int luax_assert_function(lua_State * L, int n)
{
if(!lua_isfunction(L, n))
return luaL_error(L, "Argument must be of type \"function\".");
return 0;
}
int luax_register_gc(lua_State * L, const char * mname, Module * m)
{
lua_getglobal(L, "love");
lua_getfield(L, -1, "__fin");
userdata * u = (userdata *)lua_newuserdata(L, sizeof(userdata));
u->own = true;
u->data = m;
luaL_newmetatable(L, mname);
lua_pushcfunction(L, _wrap__Module_gc);
lua_setfield(L, -2, "__gc");
lua_setmetatable(L, -2);
lua_setfield(L, -2, mname);
lua_pop(L, 2); // __fin, love
return 0;
}
int luax_register_info(lua_State * L, const char * name,
const char * provides, const char * desc, const char * author,
lua_CFunction open)
{
lua_getglobal(L, "love");
lua_getfield(L, -1, "__mod");
lua_getfield(L, -1, provides);
// Make sure it exists.
if(lua_isnil(L, -1))
{
lua_pop(L, 1);
lua_newtable(L);
lua_setfield(L, -2, provides);
lua_getfield(L, -1, provides);
}
lua_newtable(L);
lua_pushstring(L, desc);
lua_setfield(L, -2, "description");
lua_pushstring(L, author);
lua_setfield(L, -2, "author");
lua_pushcfunction(L, open);
lua_setfield(L, -2, "open");
lua_setfield(L, -2, name);
// Pop "provides", __mod, love
lua_pop(L, 3);
return 0;
}
int luax_register_module(lua_State * L, const luaL_Reg * fn, const lua_CFunction * types)
{
// Create new table for module.
lua_newtable(L);
// Register all the functions.
luaL_register(L, 0, fn);
// Register types.
if(types != 0)
for(const lua_CFunction * t = types; *t != 0; t++)
(*t)(L);
return 1;
}
int luax_preload(lua_State * L, lua_CFunction f, const char * name)
{
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
lua_pushcfunction(L, f);
lua_setfield(L, -2, name);
lua_pop(L, 2);
return 0;
}
int luax_register_type(lua_State * L, const char * tname, const luaL_Reg * fn)
{
luaL_newmetatable(L, tname);
// m.__index = m
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
// setup gc
lua_pushcfunction(L, _wrap__gc);
lua_setfield(L, -2, "__gc");
luaL_register(L, 0, fn);
lua_pop(L, 1); // Pops metatable.
return 0;
}
int luax_register_searcher(lua_State * L, lua_CFunction f)
{
// Add the package loader to the package.loaders table.
lua_getglobal(L, "package");
if(lua_isnil(L, -1))
return luaL_error(L, "Can't register searcher: package table does not exist.");
lua_getfield(L, -1, "loaders");
if(lua_isnil(L, -1))
return luaL_error(L, "Can't register searcher: package.loaders table does not exist.");
int len = lua_objlen(L, -1);
lua_pushinteger(L, len+1);
lua_pushcfunction(L, f);
lua_settable(L, -3);
lua_pop(L, 2);
return 0;
}
void luax_newtype(lua_State * L, const char * tname, bits flags, void * data, bool own)
{
userdata * u = (userdata *)lua_newuserdata(L, sizeof(userdata));
u->data = data;
u->flags = flags;
u->own = own;
luaL_newmetatable(L, tname);
lua_setmetatable(L, -2);
}
bool luax_istype(lua_State * L, int idx, love::bits type)
{
if(lua_isuserdata(L, idx) == 0)
return false;
userdata * u = (userdata *)lua_touserdata(L, idx);
return ((u->flags & type) == type);
}
int luax_getfunction(lua_State * L, const char * mod, const char * fn)
{
lua_getglobal(L, "love");
if(lua_isnil(L, -1)) return luaL_error(L, "Could not find global love!");
lua_getfield(L, -1, mod);
if(lua_isnil(L, -1)) return luaL_error(L, "Could not find love.%s!", mod);
lua_getfield(L, -1, fn);
if(lua_isnil(L, -1)) return luaL_error(L, "Could not find love.%s.%s!", mod, fn);
lua_remove(L, -2); // remove mod
lua_remove(L, -2); // remove fn
return 0;
}
int luax_convobj(lua_State * L, int idx, const char * mod, const char * fn)
{
// Convert string to a file.
luax_getfunction(L, mod, fn);
lua_pushvalue(L, idx); // The initial argument.
lua_call(L, 1, 1); // Call the function, one arg, one return value.
lua_replace(L, idx); // Replace the initial argument with the new object.
return 0;
}
int luax_strtofile(lua_State * L, int idx)
{
return luax_convobj(L, idx, "filesystem", "newFile");
}
int luax_filetodata(lua_State * L, int idx)
{
return luax_convobj(L, idx, "filesystem", "read");
}
} // love
+107
View File
@@ -0,0 +1,107 @@
/**
* Copyright (c) 2006-2009 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_RUNTIME_H
#define LOVE_RUNTIME_H
#include "types.h"
#include "Module.h"
// Lua
extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
namespace love
{
// Type used for storing constants
// in an array.
typedef struct lua_constant_entry
{
const char * name;
int value;
} lua_constant_entry;
class Module;
void luax_printstack(lua_State * L);
bool luax_toboolean(lua_State * L, int idx);
void luax_pushboolean(lua_State * L, bool b);
bool luax_optboolean(lua_State * L, int idx, bool b);
int luax_assert_argc(lua_State * L, int lower);
int luax_assert_argc(lua_State * L, int lower, int upper);
int luax_assert_function(lua_State * L, int n);
int luax_register_gc(lua_State * L, const char * mname, Module * module);
int luax_register_info(lua_State * L, const char * name,
const char * provides, const char * desc, const char * author,
lua_CFunction open);
int luax_register_module(lua_State * L, const luaL_Reg * fn, const lua_CFunction * types);
int luax_preload(lua_State * L, lua_CFunction f, const char * name);
int luax_register_type(lua_State * L, const char * tname, const luaL_Reg * fn);
int luax_register_searcher(lua_State * L, lua_CFunction f);
void luax_newtype(lua_State * L, const char * tname, bits flags, void * data, bool own = true);
bool luax_istype(lua_State * L, int idx, love::bits type);
// Gets a function love.mod.fn.
int luax_getfunction(lua_State * L, const char * mod, const char * fn);
/**
* Converts an object into another object
* by the specified function mod.fn. The function must accept
* a single file as a parameter, and return one value.
*
* Note that the initial object is converted, i.e. replaced.
**/
int luax_convobj(lua_State * L, int idx, const char * mod, const char * fn);
/**
* Converts a string into a File object. Note that the
* string is replaced by the new File object at the
* specified index, and NOT pushed onto the stack.
**/
int luax_strtofile(lua_State * L, int idx);
template <typename T>
T * luax_checktype(lua_State * L, int idx, const char * tname, love::bits type)
{
if(lua_isuserdata(L, idx) == 0)
luaL_error(L, "Incorrect parameter type: expected userdata.");
userdata * u = (userdata *)lua_touserdata(L, idx);
if((u->flags & type) != type)
luaL_error(L, "Incorrect parameter type: expected %s", tname);
return (T *)u->data;
}
} // love
#endif // LOVE_RUNTIME_H
+158
View File
@@ -0,0 +1,158 @@
/**
* Copyright (c) 2006-2009 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_TYPES_H
#define LOVE_TYPES_H
// STD
#include <bitset>
namespace love
{
enum
{
// Cross-module types.
LOVE_OBJECT_ID = 0,
LOVE_DATA_ID,
// Filesystem.
LOVE_FILESYSTEM_FILE_ID,
LOVE_FILESYSTEM_FILE_DATA_ID,
// Graphics
LOVE_GRAPHICS_DRAWABLE_ID,
LOVE_GRAPHICS_IMAGE_ID,
LOVE_GRAPHICS_FRAME_ID,
LOVE_GRAPHICS_ANIMATION_ID,
LOVE_GRAPHICS_COLOR_ID,
LOVE_GRAPHICS_FONT_ID,
LOVE_GRAPHICS_PARTICLE_SYSTEM_ID,
LOVE_GRAPHICS_SPRITE_BATCH_ID,
LOVE_GRAPHICS_VERTEX_BUFFER_ID,
// Image
LOVE_IMAGE_IMAGE_DATA_ID,
// Audio
LOVE_AUDIO_AUDIBLE_ID,
LOVE_AUDIO_SOUND_ID,
LOVE_AUDIO_MUSIC_ID,
LOVE_AUDIO_SOURCE_ID,
// Sound
LOVE_SOUND_SOUND_DATA_ID,
LOVE_SOUND_DECODER_ID,
// Physics
LOVE_PHYSICS_WORLD_ID,
LOVE_PHYSICS_CONTACT_ID,
LOVE_PHYSICS_BODY_ID,
LOVE_PHYSICS_SHAPE_ID,
LOVE_PHYSICS_CIRCLE_SHAPE_ID,
LOVE_PHYSICS_POLYGON_SHAPE_ID,
LOVE_PHYSICS_JOINT_ID,
LOVE_PHYSICS_MOUSE_JOINT_ID,
LOVE_PHYSICS_DISTANCE_JOINT_ID,
LOVE_PHYSICS_PRISMATIC_JOINT_ID,
LOVE_PHYSICS_REVOLUTE_JOINT_ID,
LOVE_PHYSICS_PULLEY_JOINT_ID,
LOVE_PHYSICS_GEAR_JOINT_ID,
// Modules.
LOVE_PHYSFS_ID,
LOVE_OPENGL_ID,
LOVE_DIRECT3D_ID,
LOVE_BOX2D_ID,
LOVE_DEVIL_ID,
LOVE_SDLSOUND_ID,
LOVE_OPENAL_ID,
// Count the number of bits needed.
LOVE_BIT_SIZE
};
typedef std::bitset<LOVE_BIT_SIZE> bits;
const bits LOVE_OBJECT_BITS = bits(1) << LOVE_OBJECT_ID;
const bits LOVE_DATA_BITS = (bits(1) << LOVE_DATA_ID) | LOVE_OBJECT_BITS;
// Filesystem.
const bits LOVE_FILESYSTEM_FILE_BITS = (bits(1) << LOVE_FILESYSTEM_FILE_ID) | LOVE_OBJECT_BITS;
const bits LOVE_FILESYSTEM_FILE_DATA_BITS = (bits(1) << LOVE_FILESYSTEM_FILE_DATA_ID) | LOVE_DATA_BITS;
// Graphics.
const bits LOVE_GRAPHICS_DRAWABLE_BITS = (bits(1) << LOVE_GRAPHICS_DRAWABLE_ID) | LOVE_OBJECT_BITS;
const bits LOVE_GRAPHICS_IMAGE_BITS = (bits(1) << LOVE_GRAPHICS_IMAGE_ID) | LOVE_GRAPHICS_DRAWABLE_BITS;
const bits LOVE_GRAPHICS_FRAME_BITS = (bits(1) << LOVE_GRAPHICS_FRAME_ID);
const bits LOVE_GRAPHICS_ANIMATION_BITS = (bits(1) << LOVE_GRAPHICS_ANIMATION_ID) | LOVE_GRAPHICS_DRAWABLE_BITS;
const bits LOVE_GRAPHICS_COLOR_BITS = (bits(1) << LOVE_GRAPHICS_COLOR_ID) | LOVE_OBJECT_BITS;
const bits LOVE_GRAPHICS_FONT_BITS = (bits(1) << LOVE_GRAPHICS_FONT_ID) | LOVE_OBJECT_BITS;
const bits LOVE_GRAPHICS_PARTICLE_SYSTEM_BITS = (bits(1) << LOVE_GRAPHICS_PARTICLE_SYSTEM_ID) | LOVE_GRAPHICS_DRAWABLE_BITS;
const bits LOVE_GRAPHICS_SPRITE_BATCH_BITS = (bits(1) << LOVE_GRAPHICS_SPRITE_BATCH_ID) | LOVE_GRAPHICS_DRAWABLE_BITS;
const bits LOVE_GRAPHICS_VERTEX_BUFFER_BITS = (bits(1) << LOVE_GRAPHICS_VERTEX_BUFFER_ID) | LOVE_GRAPHICS_DRAWABLE_BITS;
// Image.
const bits LOVE_IMAGE_IMAGE_DATA_BITS = (bits(1) << LOVE_IMAGE_IMAGE_DATA_ID) | LOVE_DATA_BITS;
// Audio.
const bits LOVE_AUDIO_AUDIBLE_BITS = (bits(1) << LOVE_AUDIO_AUDIBLE_ID) | LOVE_OBJECT_BITS;
const bits LOVE_AUDIO_SOUND_BITS = (bits(1) << LOVE_AUDIO_SOUND_ID) | LOVE_AUDIO_AUDIBLE_BITS;
const bits LOVE_AUDIO_MUSIC_BITS = (bits(1) << LOVE_AUDIO_MUSIC_ID) | LOVE_AUDIO_AUDIBLE_BITS;
const bits LOVE_AUDIO_SOURCE_BITS = (bits(1) << LOVE_AUDIO_SOURCE_ID) | LOVE_OBJECT_BITS;
// Sound.
const bits LOVE_SOUND_SOUND_DATA_BITS = (bits(1) << LOVE_SOUND_SOUND_DATA_ID) | LOVE_DATA_BITS;
const bits LOVE_SOUND_DECODER_BITS = bits(1) << LOVE_SOUND_DECODER_ID;
// Physics.
const bits LOVE_PHYSICS_WORLD_BITS = (bits(1) << LOVE_PHYSICS_WORLD_ID) | LOVE_OBJECT_BITS;
const bits LOVE_PHYSICS_CONTACT_BITS = (bits(1) << LOVE_PHYSICS_CONTACT_ID) | LOVE_OBJECT_BITS;
const bits LOVE_PHYSICS_BODY_BITS = (bits(1) << LOVE_PHYSICS_BODY_ID) | LOVE_OBJECT_BITS;
const bits LOVE_PHYSICS_SHAPE_BITS = (bits(1) << LOVE_PHYSICS_SHAPE_ID) | LOVE_OBJECT_BITS;
const bits LOVE_PHYSICS_CIRCLE_SHAPE_BITS = (bits(1) << LOVE_PHYSICS_CIRCLE_SHAPE_ID) | LOVE_PHYSICS_SHAPE_BITS;
const bits LOVE_PHYSICS_POLYGON_SHAPE_BITS = (bits(1) << LOVE_PHYSICS_POLYGON_SHAPE_ID) | LOVE_PHYSICS_SHAPE_BITS;
const bits LOVE_PHYSICS_JOINT_BITS = (bits(1) << LOVE_PHYSICS_JOINT_ID) | LOVE_OBJECT_BITS;
const bits LOVE_PHYSICS_MOUSE_JOINT_BITS = (bits(1) << LOVE_PHYSICS_MOUSE_JOINT_ID) | LOVE_PHYSICS_JOINT_BITS;
const bits LOVE_PHYSICS_DISTANCE_JOINT_BITS = (bits(1) << LOVE_PHYSICS_DISTANCE_JOINT_ID) | LOVE_PHYSICS_JOINT_BITS;
const bits LOVE_PHYSICS_PRISMATIC_JOINT_BITS = (bits(1) << LOVE_PHYSICS_PRISMATIC_JOINT_ID) | LOVE_PHYSICS_JOINT_BITS;
const bits LOVE_PHYSICS_REVOLUTE_JOINT_BITS = (bits(1) << LOVE_PHYSICS_REVOLUTE_JOINT_ID) | LOVE_PHYSICS_JOINT_BITS;
const bits LOVE_PHYSICS_PULLEY_JOINT_BITS = (bits(1) << LOVE_PHYSICS_PULLEY_JOINT_ID) | LOVE_PHYSICS_JOINT_BITS;
const bits LOVE_PHYSICS_GEAR_JOINT_BITS = (bits(1) << LOVE_PHYSICS_GEAR_JOINT_ID) | LOVE_PHYSICS_JOINT_BITS;
// Modules.
const bits LOVE_PHYSFS_BITS = bits(1) << LOVE_PHYSFS_ID;
const bits LOVE_OPENGL_BITS = bits(1) << LOVE_OPENGL_ID;
const bits LOVE_DIRECT3D_BITS = bits(1) << LOVE_DIRECT3D_ID;
const bits LOVE_BOX2D_BITS = bits(1) << LOVE_BOX2D_ID;
const bits LOVE_DEVIL_BITS = bits(1) << LOVE_DEVIL_ID;
const bits LOVE_SDLSOUND_BITS = bits(1) << LOVE_SDLSOUND_ID;
const bits LOVE_OPENAL_BITS = bits(1) << LOVE_OPENAL_ID;
// Wraps all userdata pointers.
struct userdata
{
bits flags; // Holds type information.
void * data;
bool own; // True if Lua should delete on GC.
};
} // love
#endif // LOVE_TYPES_H
+56
View File
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2006-2009 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.
**/
#include "wrap_Data.h"
namespace love
{
Data * luax_checkdata(lua_State * L, int idx)
{
return luax_checktype<Data>(L, idx, "Data", LOVE_DATA_BITS);
}
int _wrap_Data_getPointer(lua_State * L)
{
Data * t = luax_checkdata(L, 1);
lua_pushlightuserdata(L, t->getData());
return 1;
}
int _wrap_Data_getSize(lua_State * L)
{
Data * t = luax_checkdata(L, 1);
lua_pushinteger(L, t->getSize());
return 1;
}
const luaL_Reg wrap_Data_functions[] = {
{ "getPointer", _wrap_Data_getPointer },
{ "getSize", _wrap_Data_getSize },
{ 0, 0 }
};
int wrap_Data_open(lua_State * L)
{
luax_register_type(L, "Data", wrap_Data_functions);
return 0;
}
} // love
+37
View File
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2006-2009 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_WRAP_DATA_H
#define LOVE_WRAP_DATA_H
// LOVE
#include "runtime.h"
#include "Data.h"
namespace love
{
Data * luax_checkdata(lua_State * L, int idx);
int _wrap_Data_getPointer(lua_State * L);
int _wrap_Data_getSize(lua_State * L);
int wrap_Data_open(lua_State * L);
} // love
#endif // LOVE_WRAP_DATA_H