chore: lsp + format
This commit is contained in:
@@ -11,7 +11,8 @@ struct lua_State;
|
||||
|
||||
namespace esp32lua {
|
||||
|
||||
// The version sys.getAPIVersion() reports: this contract, not the firmware's build.
|
||||
// The version sys.getAPIVersion() reports: this contract, not the firmware's
|
||||
// build.
|
||||
constexpr int32_t API_VERSION = 1;
|
||||
|
||||
// Where the runtime looks for apps, their data, and shared modules.
|
||||
@@ -23,8 +24,9 @@ struct Paths {
|
||||
std::string home = "Home";
|
||||
};
|
||||
|
||||
// Firmware supplies every core provider; a null feature provider is how sys.hasFeature()
|
||||
// answers false, and its namespace additions are simply never registered.
|
||||
// Firmware supplies every core provider; a null feature provider is how
|
||||
// sys.hasFeature() answers false, and its namespace additions are simply never
|
||||
// registered.
|
||||
struct Providers {
|
||||
LogProvider* log = nullptr;
|
||||
SettingsProvider* settings = nullptr;
|
||||
@@ -41,7 +43,7 @@ struct Providers {
|
||||
};
|
||||
|
||||
class Runtime {
|
||||
public:
|
||||
public:
|
||||
explicit Runtime(const Providers& providers, const Paths& paths = Paths());
|
||||
~Runtime();
|
||||
|
||||
@@ -53,11 +55,14 @@ class Runtime {
|
||||
void close();
|
||||
lua_State* state() const { return state_; }
|
||||
|
||||
// Replaces the running app with a fresh lua_State, loads <apps>/<path>/main.lua, and calls
|
||||
// init(arg). A failure leaves no app running rather than a half-built one.
|
||||
bool startApp(const std::string& path, const std::string& arg = std::string());
|
||||
// Replaces the running app with a fresh lua_State, loads
|
||||
// <apps>/<path>/main.lua, and calls init(arg). A failure leaves no app
|
||||
// running rather than a half-built one.
|
||||
bool startApp(const std::string& path,
|
||||
const std::string& arg = std::string());
|
||||
bool hasApp() const { return !appPath_.empty(); }
|
||||
// The app-relative route, its immutable first component, and the title the app chose.
|
||||
// The app-relative route, its immutable first component, and the title the
|
||||
// app chose.
|
||||
const std::string& appPath() const { return appPath_; }
|
||||
std::string appId() const;
|
||||
std::string appDataPath() const;
|
||||
@@ -65,16 +70,19 @@ class Runtime {
|
||||
void setAppTitle(const std::string& title) { appTitle_ = title; }
|
||||
bool hasFeature(const std::string& feature) const;
|
||||
|
||||
// sys.launch/replace/back record intent and return; swapping the lua_State inside a callback
|
||||
// would free the VM that is still executing. The firmware applies it between batches.
|
||||
void requestLaunch(const std::string& path, const std::string& arg, bool replace);
|
||||
// sys.launch/replace/back record intent and return; swapping the lua_State
|
||||
// inside a callback would free the VM that is still executing. The firmware
|
||||
// applies it between batches.
|
||||
void requestLaunch(const std::string& path, const std::string& arg,
|
||||
bool replace);
|
||||
void requestBack();
|
||||
bool hasPendingNavigation() const { return pending_.kind != Pending::None; }
|
||||
// Whether sys.back() would return somewhere rather than land on the launcher, which is what
|
||||
// firmware chrome needs to decide whether to offer a back control.
|
||||
// Whether sys.back() would return somewhere rather than land on the launcher,
|
||||
// which is what firmware chrome needs to decide whether to offer a back
|
||||
// control.
|
||||
bool canGoBack() const { return !history_.empty(); }
|
||||
// Loads whatever was requested. False means the app failed to start or history ran out at the
|
||||
// launcher, in which case no app is running.
|
||||
// Loads whatever was requested. False means the app failed to start or
|
||||
// history ran out at the launcher, in which case no app is running.
|
||||
bool applyPendingNavigation();
|
||||
|
||||
LogProvider& log() const { return *providers_.log; }
|
||||
@@ -91,9 +99,10 @@ class Runtime {
|
||||
|
||||
ui::Tree& tree() { return tree_; }
|
||||
|
||||
// Entry points into the app. The firmware decides whether an event reaches the app at all --
|
||||
// jitter, chrome and debouncing are its business -- and the runtime decides what the app sees.
|
||||
// Only a failed init() stops an app; every other callback logs and carries on.
|
||||
// Entry points into the app. The firmware decides whether an event reaches
|
||||
// the app at all -- jitter, chrome and debouncing are its business -- and the
|
||||
// runtime decides what the app sees. Only a failed init() stops an app; every
|
||||
// other callback logs and carries on.
|
||||
bool callInit(const std::string& arg);
|
||||
void callDraw(int32_t deltaMs);
|
||||
// An Up phase also fires the on_touch tap alias, in that order.
|
||||
@@ -101,7 +110,8 @@ class Runtime {
|
||||
// A release also fires the on_button tap alias, in that order.
|
||||
void callButton(const std::string& button, bool pressed);
|
||||
|
||||
// Timer identity and callback retention are the runtime's; deadlines are the firmware's.
|
||||
// Timer identity and callback retention are the runtime's; deadlines are the
|
||||
// firmware's.
|
||||
TimerId addTimer(int callbackRef, int32_t intervalMs, bool repeating);
|
||||
bool cancelTimer(TimerId id);
|
||||
// Called on the Lua thread when a scheduled deadline elapses.
|
||||
@@ -109,7 +119,7 @@ class Runtime {
|
||||
|
||||
static Runtime* from(lua_State* state);
|
||||
|
||||
private:
|
||||
private:
|
||||
struct Timer {
|
||||
int callbackRef;
|
||||
bool repeating;
|
||||
@@ -131,16 +141,17 @@ class Runtime {
|
||||
static int searchEmbedded(lua_State* state);
|
||||
static int loadFile(lua_State* state);
|
||||
|
||||
// A batch is one visit to the app, however many callbacks it fans out into: a tap fires
|
||||
// on_touch_up and then the on_touch alias, and a timer can fire inside draw. Committing per
|
||||
// callback would refresh an e-ink panel twice for one visible change, so the display is
|
||||
// committed when the outermost call returns.
|
||||
// A batch is one visit to the app, however many callbacks it fans out into: a
|
||||
// tap fires on_touch_up and then the on_touch alias, and a timer can fire
|
||||
// inside draw. Committing per callback would refresh an e-ink panel twice for
|
||||
// one visible change, so the display is committed when the outermost call
|
||||
// returns.
|
||||
class Batch {
|
||||
public:
|
||||
public:
|
||||
explicit Batch(Runtime& runtime);
|
||||
~Batch();
|
||||
|
||||
private:
|
||||
private:
|
||||
Runtime& runtime_;
|
||||
};
|
||||
|
||||
@@ -163,4 +174,4 @@ class Runtime {
|
||||
Pending pending_;
|
||||
};
|
||||
|
||||
} // namespace esp32lua
|
||||
} // namespace esp32lua
|
||||
|
||||
Reference in New Issue
Block a user