From 03f4db7a84bd069dae267c7666d5eb1539c153f7 Mon Sep 17 00:00:00 2001 From: Face <69168154+face-hh@users.noreply.github.com> Date: Tue, 9 Sep 2025 18:19:36 +0300 Subject: [PATCH] gurt.width(), gurt.height() --- README.md | 2 +- docs/docs/lua/intro.md | 19 +++++++++++ flumi/Scripts/Utils/Lua/ThreadedVM.gd | 47 +++++++++++++++++++++++++-- site/src/routes/+page.svelte | 2 +- 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 34df8b1..e60be70 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [Website](https://gurted.com/) | [Docs](https://docs.gurted.com/) | [License](LICENSE) | [YouTube video](https://www.youtube.com) Gurted is an ecosystem similar to the World Wide Web, it features: -- ⚡ A custom protocol (TCP-based) named `GURT://` with mendatory TLS secutity with a [spec](docs.gurted.com) +- ⚡ A custom protocol (TCP-based) named `GURT://` with mandatory TLS security with a [spec](docs.gurted.com) - 🌐 A custom **wayfinder** (browser) written in Rust and GDScript with [Godot](https://godotengine.org/) - 📄 A custom engine for HTML, CSS, and ***Lua*** (no JavaScript) - 🏷️ A custom **DNS** that allows users to create domains with TLDs such as `.based`, `.aura`, `.twin`, and many more diff --git a/docs/docs/lua/intro.md b/docs/docs/lua/intro.md index d9b99ca..6201f98 100644 --- a/docs/docs/lua/intro.md +++ b/docs/docs/lua/intro.md @@ -112,6 +112,25 @@ end -- Get all values for a parameter (for repeated params) local tags = gurt.location.query.getAll('tag') ``` + +### gurt.width() + +Gets the available width of the site page viewport in pixels. + +```lua +local pageWidth = gurt.width() +trace.log('Page width: ' .. pageWidth .. ' pixels') +``` + +### gurt.height() + +Gets the available height of the site page viewport in pixels. + +```lua +local pageHeight = gurt.height() +trace.log('Page height: ' .. pageHeight .. ' pixels') +``` + ## Global: trace The global trace table for logging messages to the console. diff --git a/flumi/Scripts/Utils/Lua/ThreadedVM.gd b/flumi/Scripts/Utils/Lua/ThreadedVM.gd index 3d3ed40..4a5764f 100644 --- a/flumi/Scripts/Utils/Lua/ThreadedVM.gd +++ b/flumi/Scripts/Utils/Lua/ThreadedVM.gd @@ -359,6 +359,12 @@ func _setup_threaded_gurt_api(): lua_vm.lua_setfield(-2, "on") lua_vm.lua_setfield(-2, "body") + lua_vm.lua_pushcallable(_gurt_get_width_handler, "gurt.width") + lua_vm.lua_setfield(-2, "width") + + lua_vm.lua_pushcallable(_gurt_get_height_handler, "gurt.height") + lua_vm.lua_setfield(-2, "height") + lua_vm.lua_setglobal("gurt") func _setup_additional_lua_apis(): @@ -499,9 +505,46 @@ func _set_interval_handler(vm: LuauVM) -> int: func get_current_href() -> String: var main_node = Engine.get_main_loop().current_scene + return main_node.current_domain + +func _gurt_get_width_handler(vm: LuauVM) -> int: + var result = [0.0] + call_deferred("_get_width_sync", result) + while result[0] == 0.0: + OS.delay_msec(1) + vm.lua_pushnumber(result[0]) + return 1 + +func _gurt_get_height_handler(vm: LuauVM) -> int: + var result = [0.0] + call_deferred("_get_height_sync", result) + while result[0] == 0.0: + OS.delay_msec(1) + vm.lua_pushnumber(result[0]) + return 1 + +func _get_width_sync(result: Array): + var main_node = Engine.get_main_loop().current_scene if main_node: - return main_node.current_domain - return "" + var active_tab = main_node.get_active_tab() + if active_tab and active_tab.website_container: + result[0] = active_tab.website_container.size.x + else: + result[0] = 1024.0 + else: + result[0] = 1024.0 + +func _get_height_sync(result: Array): + var main_node = Engine.get_main_loop().current_scene + if main_node: + var active_tab = main_node.get_active_tab() + if active_tab and active_tab.website_container: + result[0] = active_tab.website_container.size.y + else: + result[0] = 768.0 + else: + result[0] = 768.0 + func _gurt_select_handler(vm: LuauVM) -> int: var selector: String = vm.luaL_checkstring(1) diff --git a/site/src/routes/+page.svelte b/site/src/routes/+page.svelte index 8b00778..0ea8223 100644 --- a/site/src/routes/+page.svelte +++ b/site/src/routes/+page.svelte @@ -272,7 +272,7 @@
{`