feat(sys): expose canGoBack for the chrome that offers the control

This commit is contained in:
2026-08-04 20:55:16 -04:00
parent 3f26c4ff10
commit 2fc3abc487
2 changed files with 26 additions and 12 deletions
+10 -6
View File
@@ -36,19 +36,23 @@ function sys.getAppDataPath() end
---@param title string
function sys.setAppTitle(title) end
---Launches /.lua/apps/<path>/main.lua and pushes the current route.
---@param path string App-relative directory path; traversal is rejected.
---@param arg? string Passed to init(arg).
---Launches a route, which main.lua resolves, and pushes the current one.
---@param path string App-relative route; traversal is rejected.
---@param arg? string Passed to main.start(route, arg).
function sys.launch(path, arg) end
---Launches an app path without retaining the current route.
---@param path string App-relative directory path; traversal is rejected.
---@param arg? string Passed to init(arg).
---Launches a route without retaining the current one.
---@param path string App-relative route; traversal is rejected.
---@param arg? string Passed to main.start(route, arg).
function sys.replace(path, arg) end
---Returns to the previous app, or the launcher when history is empty.
function sys.back() end
---Whether sys.back() would return somewhere rather than land on the launcher, which is what chrome needs to decide whether to offer a back control.
---@return boolean
function sys.canGoBack() end
---Returns heap statistics.
---@return integer freeBytes
---@return integer totalBytes
+16 -6
View File
@@ -50,6 +50,10 @@ int back(lua_State* state) {
Runtime::from(state)->requestBack();
return 0;
}
int canGoBack(lua_State* state) {
lua_pushboolean(state, Runtime::from(state)->canGoBack());
return 1;
}
int getMemory(lua_State* state) {
const MemoryInfo memory = Runtime::from(state)->sys().memory();
@@ -88,16 +92,22 @@ const luaL_Reg FUNCTIONS[] = {
// --- Changes the running app's display title.
// @param title string
{"setAppTitle", setAppTitle},
// --- Launches /.lua/apps/<path>/main.lua and pushes the current route.
// @param path string App-relative directory path; traversal is rejected.
// @param arg string|nil Passed to init(arg).
// --- Launches a route, which main.lua resolves, and pushes the current
// one.
// @param path string App-relative route; traversal is rejected.
// @param arg string|nil Passed to main.start(route, arg).
{"launch", launch},
// --- Launches an app path without retaining the current route.
// @param path string App-relative directory path; traversal is rejected.
// @param arg string|nil Passed to init(arg).
// --- Launches a route without retaining the current one.
// @param path string App-relative route; traversal is rejected.
// @param arg string|nil Passed to main.start(route, arg).
{"replace", replace},
// --- Returns to the previous app, or the launcher when history is empty.
{"back", back},
// --- Whether sys.back() would return somewhere rather than land on the
// launcher, which is what chrome needs to decide whether to offer a back
// control.
// @return boolean
{"canGoBack", canGoBack},
// --- Returns heap statistics.
// @return integer freeBytes
// @return integer totalBytes