-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,734 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
namespace love | ||
{ | ||
#define R_UNLESS(res_expr, throw_result) \ | ||
({ \ | ||
const auto _tmp_r_try_rc = (res_expr); \ | ||
if (res_expr < 0) \ | ||
return (throw_result); \ | ||
}) // namespace love | ||
} // namespace love |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#pragma once | ||
|
||
#include "common/module.hpp" | ||
#include "utility/map.hpp" | ||
|
||
namespace love | ||
{ | ||
template<class T> | ||
class SystemBase : public Module | ||
{ | ||
public: | ||
enum PowerState | ||
{ | ||
POWER_UNKNOWN, | ||
POWER_BATTERY, | ||
POWER_NO_BATTERY, | ||
POWER_CHARGING, | ||
POWER_CHARGED, | ||
POWER_MAX_ENUM | ||
}; | ||
|
||
enum NetworkState | ||
{ | ||
NETWORK_UNKNOWN, | ||
NETWORK_DISCONNECTED, | ||
NETWORK_CONNECTED, | ||
NETWORK_MAX_ENUM | ||
}; | ||
|
||
SystemBase() : Module(M_SYSTEM, "love.system") | ||
{} | ||
|
||
virtual ~SystemBase() | ||
{} | ||
|
||
static const char* getOS() | ||
{ | ||
return __OS__; | ||
} | ||
|
||
void setClipboardText(const std::string& text) | ||
{ | ||
this->clipboard = text; | ||
} | ||
|
||
const std::string& getClipboardText() const | ||
{ | ||
return this->clipboard; | ||
} | ||
|
||
struct FriendInfo | ||
{ | ||
std::string username; | ||
std::string friendCode; | ||
}; | ||
|
||
struct SystemInfo | ||
{ | ||
std::string version; | ||
std::string model; | ||
}; | ||
|
||
// clang-format off | ||
STRINGMAP_DECLARE(powerStates, PowerState, | ||
{ "unknown", POWER_UNKNOWN }, | ||
{ "battery", POWER_BATTERY }, | ||
{ "nobattery", POWER_NO_BATTERY }, | ||
{ "charging", POWER_CHARGING }, | ||
{ "charged", POWER_CHARGED } | ||
); | ||
|
||
STRINGMAP_DECLARE(networkStates, NetworkState, | ||
{ "unknown", NETWORK_UNKNOWN }, | ||
{ "disconnected", NETWORK_DISCONNECTED }, | ||
{ "connected", NETWORK_CONNECTED } | ||
); | ||
// clang-format on | ||
|
||
private: | ||
std::string clipboard; | ||
}; | ||
} // namespace love |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include "common/luax.hpp" | ||
#include "modules/system/System.hpp" | ||
|
||
namespace Wrap_System | ||
{ | ||
int getProcessorCount(lua_State* L); | ||
|
||
int getPowerInfo(lua_State* L); | ||
|
||
int getClipboardText(lua_State* L); | ||
|
||
int setClipboardText(lua_State* L); | ||
|
||
int vibrate(lua_State* L); | ||
|
||
int openURL(lua_State* L); | ||
|
||
int hasBackgroundMusic(lua_State* L); | ||
|
||
int getPreferredLocales(lua_State* L); | ||
|
||
int getNetworkInfo(lua_State* L); | ||
|
||
int getInfo(lua_State* L); | ||
|
||
int getOS(lua_State* L); | ||
|
||
int getPlayCoins(lua_State* L); | ||
|
||
int setPlayCoins(lua_State* L); | ||
|
||
int open(lua_State* L); | ||
} // namespace Wrap_System |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#pragma once | ||
|
||
#include "common/Object.hpp" | ||
#include "common/Variant.hpp" | ||
|
||
#include <condition_variable> | ||
#include <mutex> | ||
|
||
#include <queue> | ||
|
||
namespace love | ||
{ | ||
class Channel : public Object | ||
{ | ||
public: | ||
static Type type; | ||
|
||
Channel(); | ||
|
||
virtual ~Channel() | ||
{} | ||
|
||
uint64_t push(const Variant& value); | ||
|
||
bool supply(const Variant& value); | ||
|
||
bool supply(const Variant& value, double timeout); | ||
|
||
bool pop(Variant* value); | ||
|
||
bool demand(Variant* value); | ||
|
||
bool demand(Variant* value, double timeout); | ||
|
||
bool peek(Variant* value); | ||
|
||
bool hasRead(uint64_t id); | ||
|
||
int getCount(); | ||
|
||
void clear(); | ||
|
||
void lockMutex(); | ||
|
||
void unlockMutex(); | ||
|
||
std::recursive_mutex& getMutex() | ||
{ | ||
return this->mutex; | ||
} | ||
|
||
private: | ||
uint64_t sent; | ||
uint64_t received; | ||
|
||
std::recursive_mutex mutex; | ||
std::condition_variable_any condvar; | ||
|
||
std::queue<Variant> queue; | ||
}; | ||
} // namespace love |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "common/Data.hpp" | ||
#include "common/Object.hpp" | ||
#include "common/StrongRef.hpp" | ||
#include "common/Variant.hpp" | ||
|
||
#include "modules/thread/Threadable.hpp" | ||
|
||
#include <vector> | ||
|
||
namespace love | ||
{ | ||
class LuaThread : public Threadable | ||
{ | ||
public: | ||
static Type type; | ||
|
||
LuaThread(const std::string& name, Data* code); | ||
|
||
virtual ~LuaThread() | ||
{} | ||
|
||
void run() override; | ||
|
||
const std::string& getError() const; | ||
|
||
bool hasError() const | ||
{ | ||
return this->_hasError; | ||
} | ||
|
||
bool start(const std::vector<Variant>& args); | ||
|
||
private: | ||
void onError(); | ||
|
||
StrongRef<Data> code; | ||
|
||
std::string name; | ||
std::string error; | ||
|
||
bool _hasError; | ||
|
||
std::vector<Variant> args; | ||
}; | ||
} // namespace love |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include "common/Object.hpp" | ||
|
||
#include <mutex> | ||
#include <thread> | ||
|
||
namespace love | ||
{ | ||
class Threadable; | ||
|
||
class Thread | ||
{ | ||
public: | ||
Thread(Threadable* threadable); | ||
|
||
virtual ~Thread(); | ||
|
||
bool start(); | ||
|
||
void wait(); | ||
|
||
bool isRunning(); | ||
|
||
private: | ||
static int runner(void* data); | ||
|
||
Threadable* threadable; | ||
std::atomic<bool> running; | ||
|
||
std::thread thread; | ||
std::mutex mutex; | ||
}; | ||
} // namespace love |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include "common/Data.hpp" | ||
#include "common/Module.hpp" | ||
#include "utility/map.hpp" | ||
|
||
#include "modules/thread/Channel.hpp" | ||
#include "modules/thread/LuaThread.hpp" | ||
#include "modules/thread/Thread.hpp" | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
namespace love | ||
{ | ||
class ThreadModule : public Module | ||
{ | ||
public: | ||
ThreadModule(); | ||
|
||
virtual ~ThreadModule() | ||
{} | ||
|
||
LuaThread* newThread(const std::string& name, Data* data) const; | ||
|
||
Channel* newChannel() const; | ||
|
||
Channel* getChannel(const std::string& name); | ||
|
||
private: | ||
std::map<std::string, StrongRef<Channel>> channels; | ||
std::recursive_mutex mutex; | ||
}; | ||
} // namespace love |
Oops, something went wrong.