mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Add love.thread.getKeys (issue #276)
This commit is contained in:
@@ -185,6 +185,16 @@ namespace thread
|
|||||||
shared[name] = v;
|
shared[name] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> ThreadData::getKeys()
|
||||||
|
{
|
||||||
|
std::vector<std::string> keys;
|
||||||
|
for (std::map<std::string, ThreadVariant*>::iterator it = shared.begin(); it != shared.end(); it++)
|
||||||
|
{
|
||||||
|
keys.push_back(it->first);
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
Thread::Thread(love::thread::ThreadModule *module, const std::string & name, love::Data *data)
|
Thread::Thread(love::thread::ThreadModule *module, const std::string & name, love::Data *data)
|
||||||
: handle(0), module(module), name(name), isThread(true)
|
: handle(0), module(module), name(name), isThread(true)
|
||||||
{
|
{
|
||||||
@@ -270,6 +280,11 @@ namespace thread
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Thread::getKeys()
|
||||||
|
{
|
||||||
|
return comm->getKeys();
|
||||||
|
}
|
||||||
|
|
||||||
ThreadVariant *Thread::demand(const std::string & name)
|
ThreadVariant *Thread::demand(const std::string & name)
|
||||||
{
|
{
|
||||||
ThreadVariant *v = comm->getValue(name);
|
ThreadVariant *v = comm->getValue(name);
|
||||||
|
|||||||
@@ -24,7 +24,8 @@
|
|||||||
// STL
|
// STL
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string.h>
|
#include <vector>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
// LOVE
|
// LOVE
|
||||||
#include <filesystem/File.h>
|
#include <filesystem/File.h>
|
||||||
@@ -90,6 +91,7 @@ namespace thread
|
|||||||
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);
|
||||||
|
std::vector<std::string> getKeys();
|
||||||
|
|
||||||
void *mutex;
|
void *mutex;
|
||||||
void *cond;
|
void *cond;
|
||||||
@@ -129,6 +131,7 @@ namespace thread
|
|||||||
void wait();
|
void wait();
|
||||||
std::string getName();
|
std::string getName();
|
||||||
ThreadVariant *get(const std::string & name);
|
ThreadVariant *get(const std::string & name);
|
||||||
|
std::vector<std::string> getKeys();
|
||||||
ThreadVariant *demand(const std::string & name);
|
ThreadVariant *demand(const std::string & name);
|
||||||
void clear(const std::string & name);
|
void clear(const std::string & name);
|
||||||
void set(const std::string & name, ThreadVariant *v);
|
void set(const std::string & name, ThreadVariant *v);
|
||||||
|
|||||||
@@ -128,6 +128,23 @@ namespace thread
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_Thread_getKeys(lua_State *L)
|
||||||
|
{
|
||||||
|
Thread *t = luax_checkthread(L, 1);
|
||||||
|
t->lock();
|
||||||
|
std::vector<std::string> keys = t->getKeys();
|
||||||
|
t->unlock();
|
||||||
|
lua_createtable(L, keys.size(), 0);
|
||||||
|
int i = 0;
|
||||||
|
for (std::vector<std::string>::iterator it = keys.begin(); it != keys.end(); it++)
|
||||||
|
{
|
||||||
|
lua_pushnumber(L, i++);
|
||||||
|
lua_pushlstring(L, it->c_str(), it->length());
|
||||||
|
lua_settable(L, -3);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int w_Thread_demand(lua_State *L)
|
int w_Thread_demand(lua_State *L)
|
||||||
{
|
{
|
||||||
Thread *t = luax_checkthread(L, 1);
|
Thread *t = luax_checkthread(L, 1);
|
||||||
@@ -216,6 +233,7 @@ namespace thread
|
|||||||
{ "wait", w_Thread_wait },
|
{ "wait", w_Thread_wait },
|
||||||
{ "getName", w_Thread_getName },
|
{ "getName", w_Thread_getName },
|
||||||
{ "get", w_Thread_get },
|
{ "get", w_Thread_get },
|
||||||
|
{ "getKeys", w_Thread_getKeys },
|
||||||
{ "demand", w_Thread_demand },
|
{ "demand", w_Thread_demand },
|
||||||
{ "peek", w_Thread_peek },
|
{ "peek", w_Thread_peek },
|
||||||
{ "set", w_Thread_set },
|
{ "set", w_Thread_set },
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ namespace thread
|
|||||||
int w_Thread_wait(lua_State *L);
|
int w_Thread_wait(lua_State *L);
|
||||||
int w_Thread_getName(lua_State *L);
|
int w_Thread_getName(lua_State *L);
|
||||||
int w_Thread_get(lua_State *L);
|
int w_Thread_get(lua_State *L);
|
||||||
|
int w_Thread_getKeys(lua_State *L);
|
||||||
int w_Thread_demand(lua_State *L);
|
int w_Thread_demand(lua_State *L);
|
||||||
int w_Thread_peek(lua_State *L);
|
int w_Thread_peek(lua_State *L);
|
||||||
int w_Thread_set(lua_State *L);
|
int w_Thread_set(lua_State *L);
|
||||||
|
|||||||
Reference in New Issue
Block a user