this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

gpt5-rust pt2

alice b7bf5559 620d7095

+222 -21
+144 -3
tic80_rust/Cargo.lock
··· 179 179 ] 180 180 181 181 [[package]] 182 + name = "bstr" 183 + version = "1.12.0" 184 + source = "registry+https://github.com/rust-lang/crates.io-index" 185 + checksum = "234113d19d0d7d613b40e86fb654acf958910802bcceab913a4f9e7cda03b1a4" 186 + dependencies = [ 187 + "memchr", 188 + "serde", 189 + ] 190 + 191 + [[package]] 182 192 name = "bumpalo" 183 193 version = "3.19.0" 184 194 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 325 335 checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" 326 336 327 337 [[package]] 338 + name = "either" 339 + version = "1.15.0" 340 + source = "registry+https://github.com/rust-lang/crates.io-index" 341 + checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" 342 + 343 + [[package]] 344 + name = "env_home" 345 + version = "0.1.0" 346 + source = "registry+https://github.com/rust-lang/crates.io-index" 347 + checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe" 348 + 349 + [[package]] 328 350 name = "equivalent" 329 351 version = "1.0.2" 330 352 source = "registry+https://github.com/rust-lang/crates.io-index" 331 353 checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" 354 + 355 + [[package]] 356 + name = "errno" 357 + version = "0.3.13" 358 + source = "registry+https://github.com/rust-lang/crates.io-index" 359 + checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" 360 + dependencies = [ 361 + "libc", 362 + "windows-sys 0.60.2", 363 + ] 332 364 333 365 [[package]] 334 366 name = "fdeflate" ··· 629 661 ] 630 662 631 663 [[package]] 664 + name = "linux-raw-sys" 665 + version = "0.9.4" 666 + source = "registry+https://github.com/rust-lang/crates.io-index" 667 + checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" 668 + 669 + [[package]] 632 670 name = "lock_api" 633 671 version = "0.4.13" 634 672 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 643 681 version = "0.4.27" 644 682 source = "registry+https://github.com/rust-lang/crates.io-index" 645 683 checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" 684 + 685 + [[package]] 686 + name = "lua-src" 687 + version = "547.0.0" 688 + source = "registry+https://github.com/rust-lang/crates.io-index" 689 + checksum = "1edaf29e3517b49b8b746701e5648ccb5785cde1c119062cbabbc5d5cd115e42" 690 + dependencies = [ 691 + "cc", 692 + ] 693 + 694 + [[package]] 695 + name = "luajit-src" 696 + version = "210.5.12+a4f56a4" 697 + source = "registry+https://github.com/rust-lang/crates.io-index" 698 + checksum = "b3a8e7962a5368d5f264d045a5a255e90f9aa3fc1941ae15a8d2940d42cac671" 699 + dependencies = [ 700 + "cc", 701 + "which", 702 + ] 646 703 647 704 [[package]] 648 705 name = "malloc_buf" ··· 715 772 ] 716 773 717 774 [[package]] 775 + name = "mlua" 776 + version = "0.9.9" 777 + source = "registry+https://github.com/rust-lang/crates.io-index" 778 + checksum = "d111deb18a9c9bd33e1541309f4742523bfab01d276bfa9a27519f6de9c11dc7" 779 + dependencies = [ 780 + "bstr", 781 + "mlua-sys", 782 + "num-traits", 783 + "once_cell", 784 + "rustc-hash 2.1.1", 785 + ] 786 + 787 + [[package]] 788 + name = "mlua-sys" 789 + version = "0.6.8" 790 + source = "registry+https://github.com/rust-lang/crates.io-index" 791 + checksum = "380c1f7e2099cafcf40e51d3a9f20a346977587aa4d012eae1f043149a728a93" 792 + dependencies = [ 793 + "cc", 794 + "cfg-if", 795 + "lua-src", 796 + "luajit-src", 797 + "pkg-config", 798 + ] 799 + 800 + [[package]] 718 801 name = "naga" 719 802 version = "0.13.0" 720 803 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 727 810 "indexmap 1.9.3", 728 811 "log", 729 812 "num-traits", 730 - "rustc-hash", 813 + "rustc-hash 1.1.0", 731 814 "spirv", 732 815 "termcolor", 733 816 "thiserror", ··· 1080 1163 checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" 1081 1164 1082 1165 [[package]] 1166 + name = "rustc-hash" 1167 + version = "2.1.1" 1168 + source = "registry+https://github.com/rust-lang/crates.io-index" 1169 + checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" 1170 + 1171 + [[package]] 1172 + name = "rustix" 1173 + version = "1.0.8" 1174 + source = "registry+https://github.com/rust-lang/crates.io-index" 1175 + checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" 1176 + dependencies = [ 1177 + "bitflags 2.9.3", 1178 + "errno", 1179 + "libc", 1180 + "linux-raw-sys", 1181 + "windows-sys 0.60.2", 1182 + ] 1183 + 1184 + [[package]] 1083 1185 name = "rustversion" 1084 1186 version = "1.0.22" 1085 1187 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1120 1222 ] 1121 1223 1122 1224 [[package]] 1225 + name = "serde" 1226 + version = "1.0.219" 1227 + source = "registry+https://github.com/rust-lang/crates.io-index" 1228 + checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" 1229 + dependencies = [ 1230 + "serde_derive", 1231 + ] 1232 + 1233 + [[package]] 1234 + name = "serde_derive" 1235 + version = "1.0.219" 1236 + source = "registry+https://github.com/rust-lang/crates.io-index" 1237 + checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" 1238 + dependencies = [ 1239 + "proc-macro2", 1240 + "quote", 1241 + "syn 2.0.106", 1242 + ] 1243 + 1244 + [[package]] 1123 1245 name = "shlex" 1124 1246 version = "1.3.0" 1125 1247 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1242 1364 name = "tic80_rust" 1243 1365 version = "0.1.0" 1244 1366 dependencies = [ 1367 + "mlua", 1245 1368 "pixels", 1246 1369 "winit", 1247 1370 ] ··· 1540 1663 "parking_lot", 1541 1664 "profiling", 1542 1665 "raw-window-handle", 1543 - "rustc-hash", 1666 + "rustc-hash 1.1.0", 1544 1667 "smallvec", 1545 1668 "thiserror", 1546 1669 "web-sys", ··· 1580 1703 "range-alloc", 1581 1704 "raw-window-handle", 1582 1705 "renderdoc-sys", 1583 - "rustc-hash", 1706 + "rustc-hash 1.1.0", 1584 1707 "smallvec", 1585 1708 "thiserror", 1586 1709 "wasm-bindgen", ··· 1601 1724 ] 1602 1725 1603 1726 [[package]] 1727 + name = "which" 1728 + version = "7.0.3" 1729 + source = "registry+https://github.com/rust-lang/crates.io-index" 1730 + checksum = "24d643ce3fd3e5b54854602a080f34fb10ab75e0b813ee32d00ca2b44fa74762" 1731 + dependencies = [ 1732 + "either", 1733 + "env_home", 1734 + "rustix", 1735 + "winsafe", 1736 + ] 1737 + 1738 + [[package]] 1604 1739 name = "wide" 1605 1740 version = "0.7.33" 1606 1741 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1975 2110 dependencies = [ 1976 2111 "memchr", 1977 2112 ] 2113 + 2114 + [[package]] 2115 + name = "winsafe" 2116 + version = "0.0.19" 2117 + source = "registry+https://github.com/rust-lang/crates.io-index" 2118 + checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" 1978 2119 1979 2120 [[package]] 1980 2121 name = "wit-bindgen-rt"
+1
tic80_rust/Cargo.toml
··· 6 6 [dependencies] 7 7 winit = "0.28" 8 8 pixels = "0.14" 9 + mlua = { version = "0.9", features = ["lua54", "vendored"] }
+77 -18
tic80_rust/src/main.rs
··· 1 + use std::rc::Rc; 1 2 use std::time::{Duration, Instant}; 3 + use std::cell::RefCell; 2 4 3 5 use pixels::{Error, Pixels, SurfaceTexture}; 4 6 use winit::dpi::LogicalSize; 5 7 use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}; 6 8 use winit::event_loop::{ControlFlow, EventLoop}; 7 9 use winit::window::WindowBuilder; 10 + use mlua::{Lua, Function, RegistryKey, Result as LuaResult}; 8 11 9 12 const WIDTH: u32 = 240; 10 13 const HEIGHT: u32 = 136; ··· 81 84 } 82 85 } 83 86 87 + const DEFAULT_LUA: &str = r#" 88 + -- Minimal demo using cls and pix 89 + local t = 0 90 + function BOOT() 91 + cls(0) 92 + end 93 + function TIC() 94 + if t % 30 == 0 then cls(((t // 30) % 16)) end 95 + local cx, cy = 120, 68 96 + for dx = -10, 10 do pix(cx + dx, cy, 15) end 97 + for dy = -10, 10 do pix(cx, cy + dy, 15) end 98 + t = t + 1 99 + end 100 + "#; 101 + 102 + struct LuaRunner { 103 + lua: Lua, 104 + tic_key: Option<RegistryKey>, 105 + } 106 + 107 + impl LuaRunner { 108 + fn new(fb: Rc<RefCell<Framebuffer>>, script_src: &str) -> LuaResult<Self> { 109 + let lua = Lua::new(); 110 + let tic_key = { 111 + let globals = lua.globals(); 112 + 113 + // Bind cls(color) 114 + let fb_cls = fb.clone(); 115 + let cls_fn = lua.create_function(move |_, color: Option<u8>| { 116 + fb_cls.borrow_mut().cls(color.unwrap_or(0)); 117 + Ok(()) 118 + })?; 119 + globals.set("cls", cls_fn)?; 120 + 121 + // Bind pix(x,y[,color]) -> color or nil 122 + let fb_pix = fb.clone(); 123 + let pix_fn = lua.create_function(move |_, (x, y, color): (i32, i32, Option<u8>)| { 124 + let res = fb_pix.borrow_mut().pix(x, y, color); 125 + Ok(res) 126 + })?; 127 + globals.set("pix", pix_fn)?; 128 + 129 + // Load script 130 + lua.load(script_src).set_name("cart").exec()?; 131 + 132 + // Call BOOT() if present 133 + if let Ok(boot) = globals.get::<_, Function>("BOOT") { 134 + let _ = boot.call::<_, ()>(()); 135 + } 136 + 137 + // Cache TIC if present 138 + match globals.get::<_, Option<Function>>("TIC")? { 139 + Some(f) => Some(lua.create_registry_value(f)?), 140 + None => None, 141 + } 142 + }; 143 + 144 + Ok(Self { lua, tic_key }) 145 + } 146 + 147 + fn tick(&self) { 148 + if let Some(key) = &self.tic_key { 149 + if let Ok(func) = self.lua.registry_value::<Function>(key) { 150 + let _ = func.call::<_, ()>(()); 151 + } 152 + } 153 + } 154 + } 155 + 84 156 fn run() -> Result<(), Error> { 85 157 let event_loop = EventLoop::new(); 86 158 let scale = 3.0f64; // default integer scaling ··· 95 167 let window_size = window.inner_size(); 96 168 let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, &window); 97 169 let mut pixels = Pixels::new(WIDTH, HEIGHT, surface_texture)?; 98 - 99 - let mut fb = Framebuffer::new(); 170 + let fb = Rc::new(RefCell::new(Framebuffer::new())); 100 171 let mut ticker = Ticker::new(); 101 172 102 - // Micro-demo state 103 - let mut frame_count: u64 = 0; 173 + // Lua runner with default script 174 + let lua_runner = LuaRunner::new(fb.clone(), DEFAULT_LUA).ok(); 104 175 105 176 event_loop.run(move |event, _, control_flow| { 106 177 *control_flow = ControlFlow::Poll; ··· 117 188 }, 118 189 Event::MainEventsCleared => { 119 190 if ticker.should_tick() { 120 - if frame_count % 30 == 0 { 121 - let color_idx = ((frame_count / 30) % 16) as u8; 122 - fb.cls(color_idx); 123 - } 124 - let cx = (WIDTH / 2) as i32; 125 - let cy = (HEIGHT / 2) as i32; 126 - for dx in -10..=10 { 127 - let _ = fb.pix(cx + dx, cy, Some(15)); 128 - } 129 - for dy in -10..=10 { 130 - let _ = fb.pix(cx, cy + dy, Some(15)); 131 - } 132 - frame_count += 1; 191 + if let Some(r) = &lua_runner { r.tick(); } 133 192 window.request_redraw(); 134 193 } 135 194 } 136 195 Event::RedrawRequested(_) => { 137 196 let frame = pixels.frame_mut(); 138 - fb.blit_to_rgba(frame); 197 + fb.borrow().blit_to_rgba(frame); 139 198 let _ = pixels.render(); 140 199 } 141 200 _ => {}