|
1 | 1 | //! Program Loading and Execution |
2 | 2 |
|
3 | | -use crate::{osprint, osprintln, FILESYSTEM}; |
| 3 | +use crate::{osprintln, FILESYSTEM}; |
4 | 4 |
|
5 | 5 | #[allow(unused)] |
6 | 6 | static CALLBACK_TABLE: neotron_api::Api = neotron_api::Api { |
@@ -230,15 +230,23 @@ impl TransientProgramArea { |
230 | 230 | /// an exit code that is non-zero is not considered a failure from the point |
231 | 231 | /// of view of this API. You wanted to run a program, and the program was |
232 | 232 | /// run. |
233 | | - pub fn execute(&mut self) -> Result<i32, Error> { |
| 233 | + pub fn execute(&mut self, args: &[&str]) -> Result<i32, Error> { |
234 | 234 | if self.last_entry == 0 { |
235 | 235 | return Err(Error::NothingLoaded); |
236 | 236 | } |
237 | 237 |
|
| 238 | + // We support a maximum of four arguments. |
| 239 | + let ffi_args = [ |
| 240 | + neotron_api::FfiString::new(args.get(0).unwrap_or(&"")), |
| 241 | + neotron_api::FfiString::new(args.get(1).unwrap_or(&"")), |
| 242 | + neotron_api::FfiString::new(args.get(2).unwrap_or(&"")), |
| 243 | + neotron_api::FfiString::new(args.get(3).unwrap_or(&"")), |
| 244 | + ]; |
| 245 | + |
238 | 246 | let result = unsafe { |
239 | | - let code: extern "C" fn(*const neotron_api::Api) -> i32 = |
| 247 | + let code: neotron_api::AppStartFn = |
240 | 248 | ::core::mem::transmute(self.last_entry as *const ()); |
241 | | - code(&CALLBACK_TABLE) |
| 249 | + code(&CALLBACK_TABLE, args.len(), ffi_args.as_ptr()) |
242 | 250 | }; |
243 | 251 |
|
244 | 252 | self.last_entry = 0; |
@@ -278,17 +286,6 @@ impl TransientProgramArea { |
278 | 286 | } |
279 | 287 | } |
280 | 288 |
|
281 | | -/// Application API to print things to the console. |
282 | | -#[allow(unused)] |
283 | | -extern "C" fn print_fn(data: *const u8, len: usize) { |
284 | | - let slice = unsafe { core::slice::from_raw_parts(data, len) }; |
285 | | - if let Ok(s) = core::str::from_utf8(slice) { |
286 | | - osprint!("{}", s); |
287 | | - } else { |
288 | | - // Ignore App output - not UTF-8 |
289 | | - } |
290 | | -} |
291 | | - |
292 | 289 | /// Open a file, given a path as UTF-8 string. |
293 | 290 | /// |
294 | 291 | /// If the file does not exist, or is already open, it returns an error. |
|
0 commit comments