This commit is contained in:
Bart van Strien
2010-12-19 12:31:31 +01:00
7 changed files with 1971 additions and 1947 deletions
@@ -133,6 +133,9 @@ namespace opengl
int w = luaL_checkint(L, 3); int w = luaL_checkint(L, 3);
int h = luaL_checkint(L, 4); int h = luaL_checkint(L, 4);
if (w < 0 || h < 0)
return luaL_error(L, "Can't set scissor with negative width and/or height.");
instance->setScissor(x, y, w, h); instance->setScissor(x, y, w, h);
return 0; return 0;
} }
+4
View File
@@ -153,12 +153,16 @@ namespace box2d
switch(n) switch(n)
{ {
case 4: case 4:
if (result.ref) delete result.ref;
result.ref = luax_refif(L, LUA_TFUNCTION); result.ref = luax_refif(L, LUA_TFUNCTION);
case 3: case 3:
if (remove.ref) delete remove.ref;
remove.ref = luax_refif(L, LUA_TFUNCTION); remove.ref = luax_refif(L, LUA_TFUNCTION);
case 2: case 2:
if (persist.ref) delete persist.ref;
persist.ref = luax_refif(L, LUA_TFUNCTION); persist.ref = luax_refif(L, LUA_TFUNCTION);
case 1: case 1:
if (add.ref) delete add.ref;
add.ref = luax_refif(L, LUA_TFUNCTION); add.ref = luax_refif(L, LUA_TFUNCTION);
} }
+16 -11
View File
@@ -42,7 +42,11 @@ namespace sdl
luaopen_love(L); luaopen_love(L);
#endif // LOVE_BUILD_STANDALONE #endif // LOVE_BUILD_STANDALONE
luaopen_love_thread(L); luaopen_love_thread(L);
lua_pushstring(L, comm->getName()); {
size_t len;
const char *name = comm->getName(&len);
lua_pushlstring(L, name, len);
}
luax_convobj(L, lua_gettop(L), "thread", "getThread"); luax_convobj(L, lua_gettop(L), "thread", "getThread");
lua_getglobal(L, "love"); lua_getglobal(L, "love");
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
@@ -72,14 +76,14 @@ namespace sdl
data.number = number; data.number = number;
} }
ThreadVariant::ThreadVariant(const char *string) ThreadVariant::ThreadVariant(const char *string, size_t len)
{ {
type = STRING; type = STRING;
size_t len = strlen(string);
char *buf = new char[len+1]; char *buf = new char[len+1];
memset(buf, 0, len+1); memset(buf, 0, len+1);
memcpy(buf, string, len); memcpy(buf, string, len);
data.string = buf; data.string.str = buf;
data.string.len = len;
} }
ThreadVariant::ThreadVariant(void *userdata) ThreadVariant::ThreadVariant(void *userdata)
@@ -103,7 +107,7 @@ namespace sdl
switch(type) switch(type)
{ {
case STRING: case STRING:
delete[] data.string; delete[] data.string.str;
break; break;
case FUSERDATA: case FUSERDATA:
((love::Object *) data.userdata)->release(); ((love::Object *) data.userdata)->release();
@@ -113,10 +117,9 @@ namespace sdl
} }
} }
ThreadData::ThreadData(const char *name, const char *code, void *mutex, void *cond) ThreadData::ThreadData(const char *name, size_t len, const char *code, void *mutex, void *cond)
: mutex(mutex), cond(cond) : mutex(mutex), cond(cond), len(len)
{ {
size_t len = strlen(name);
this->name = new char[len+1]; this->name = new char[len+1];
memset(this->name, 0, len+1); memset(this->name, 0, len+1);
memcpy(this->name, name, len); memcpy(this->name, name, len);
@@ -142,8 +145,10 @@ namespace sdl
return code; return code;
} }
const char *ThreadData::getName() const char *ThreadData::getName(size_t *len)
{ {
if (len)
*len = this->len;
return name; return name;
} }
@@ -180,7 +185,7 @@ namespace sdl
memcpy(this->data, data->getData(), len); memcpy(this->data, data->getData(), len);
mutex = SDL_CreateMutex(); mutex = SDL_CreateMutex();
cond = SDL_CreateCond(); cond = SDL_CreateCond();
comm = new ThreadData(name.c_str(), this->data, mutex, cond); comm = new ThreadData(name.c_str(), name.length(), this->data, mutex, cond);
} }
Thread::Thread(love::thread::ThreadModule *module, const std::string & name) Thread::Thread(love::thread::ThreadModule *module, const std::string & name)
@@ -189,7 +194,7 @@ namespace sdl
module->retain(); module->retain();
mutex = SDL_CreateMutex(); mutex = SDL_CreateMutex();
cond = SDL_CreateCond(); cond = SDL_CreateCond();
comm = new ThreadData(name.c_str(), NULL, mutex, cond); comm = new ThreadData(name.c_str(), name.length(), NULL, mutex, cond);
} }
Thread::~Thread() Thread::~Thread()
+8 -4
View File
@@ -55,7 +55,7 @@ namespace sdl
public: public:
ThreadVariant(bool boolean); ThreadVariant(bool boolean);
ThreadVariant(double number); ThreadVariant(double number);
ThreadVariant(const char *string); ThreadVariant(const char *string, size_t len);
ThreadVariant(void *userdata); ThreadVariant(void *userdata);
ThreadVariant(Type udatatype, void *userdata); ThreadVariant(Type udatatype, void *userdata);
virtual ~ThreadVariant(); virtual ~ThreadVariant();
@@ -64,7 +64,10 @@ namespace sdl
{ {
bool boolean; bool boolean;
double number; double number;
const char *string; struct {
const char *str;
size_t len;
} string;
void *userdata; void *userdata;
} data; } data;
Type udatatype; Type udatatype;
@@ -77,12 +80,13 @@ namespace sdl
char *code; char *code;
char *name; char *name;
std::map<std::string, ThreadVariant*> shared; std::map<std::string, ThreadVariant*> shared;
size_t len;
public: public:
ThreadData(const char *name, const char *code, void *mutex, void *cond); ThreadData(const char *name, size_t len, const char *code, void *mutex, void *cond);
~ThreadData(); ~ThreadData();
const char *getCode(); const char *getCode();
const char *getName(); const char *getName(size_t *len = 0);
ThreadVariant* getValue(const std::string & name); ThreadVariant* getValue(const std::string & name);
void clearValue(const std::string & name); void clearValue(const std::string & name);
void setValue(const std::string & name, ThreadVariant *v); void setValue(const std::string & name, ThreadVariant *v);
+6 -4
View File
@@ -80,7 +80,7 @@ namespace sdl
lua_pushnumber(L, v->data.number); lua_pushnumber(L, v->data.number);
break; break;
case STRING: case STRING:
lua_pushstring(L, v->data.string); lua_pushlstring(L, v->data.string.str, v->data.string.len);
break; break;
case LUSERDATA: case LUSERDATA:
lua_pushlightuserdata(L, v->data.userdata); lua_pushlightuserdata(L, v->data.userdata);
@@ -122,7 +122,7 @@ namespace sdl
lua_pushnumber(L, v->data.number); lua_pushnumber(L, v->data.number);
break; break;
case STRING: case STRING:
lua_pushstring(L, v->data.string); lua_pushlstring(L, v->data.string.str, v->data.string.len);
break; break;
case LUSERDATA: case LUSERDATA:
lua_pushlightuserdata(L, v->data.userdata); lua_pushlightuserdata(L, v->data.userdata);
@@ -163,7 +163,7 @@ namespace sdl
lua_pushnumber(L, v->data.number); lua_pushnumber(L, v->data.number);
break; break;
case STRING: case STRING:
lua_pushstring(L, v->data.string); lua_pushlstring(L, v->data.string.str, v->data.string.len);
break; break;
case LUSERDATA: case LUSERDATA:
lua_pushlightuserdata(L, v->data.userdata); lua_pushlightuserdata(L, v->data.userdata);
@@ -215,7 +215,9 @@ namespace sdl
} }
else if (lua_isstring(L, 3)) else if (lua_isstring(L, 3))
{ {
v = new ThreadVariant(lua_tostring(L, 3)); size_t len;
const char *str = lua_tolstring(L, 3, &len);
v = new ThreadVariant(str, len);
} }
else if (lua_islightuserdata(L, 3)) else if (lua_islightuserdata(L, 3))
{ {
+1 -1
View File
@@ -195,7 +195,7 @@ function love.boot()
love.filesystem.init(abs_arg0) love.filesystem.init(abs_arg0)
-- Is this one of those fancy "fused" games? -- Is this one of those fancy "fused" games?
local can_has_game = pcall(love.filesystem.setSource, abs_arg0) local can_has_game = love.filesystem.isFile(abs_arg0) and not love.filesystem.isDirectory(abs_arg0) and pcall(love.filesystem.setSource, abs_arg0)
if not can_has_game and o.game.set and o.game.arg[1] then if not can_has_game and o.game.set and o.game.arg[1] then
local full_source = love.path.getfull(o.game.arg[1]) local full_source = love.path.getfull(o.game.arg[1])
+1933 -1927
View File
File diff suppressed because it is too large Load Diff