Skip to content

Commit

Permalink
fix: added argv table to embed saturnus runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmasoldi3r committed Dec 7, 2023
1 parent 8b14ce2 commit ddc657c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions janus/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// use std::process::Command;

fn main() {
// let _ = Command::new("cargo")
// .arg("build")
// .arg("--release")
// .current_dir("../runtime")
// .output()
// .unwrap();
}
15 changes: 0 additions & 15 deletions janus/build.rs.disabled

This file was deleted.

4 changes: 2 additions & 2 deletions janus/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ impl ExitCode {
ExitCode::TargetNotSupported => exit(3),
ExitCode::UnknownModuleSystem => exit(4),
ExitCode::CannotCreateDistFolders => exit(5),
ExitCode::CannotResolveDependencies => exit(6),
// ExitCode::CannotResolveDependencies => exit(6),
ExitCode::FailedCompilation => exit(7),
ExitCode::Unknown => exit(-1),
// ExitCode::Unknown => exit(-1),
ExitCode::Ok => exit(0),
}
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ version = "0.1.0"

[dependencies]
rlua = "0.19.4"

# egui = "0.24.1"
21 changes: 16 additions & 5 deletions runtime/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
io::{self, BufReader, Read, Seek},
};

use rlua::{InitFlags, StdLib};
use rlua::{InitFlags, Result, StdLib};

const INDEX_SIZE: usize = 8;

Expand All @@ -23,22 +23,33 @@ fn get_size() -> io::Result<i64> {
Ok(size)
}

fn main() -> io::Result<()> {
fn load_script() -> io::Result<Vec<u8>> {
let size = get_size()?;
let mut buffer = Vec::<u8>::new();
let file = open_file()?;
let mut bf = BufReader::new(file);
bf.seek(io::SeekFrom::End(-(size + INDEX_SIZE as i64)))?;
bf.read_to_end(&mut buffer)?;
buffer.truncate(buffer.len() - INDEX_SIZE);
Ok(buffer)
}

fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect();
let script = load_script()?;
// See https://github.com/amethyst/rlua/issues/264
unsafe {
let lua = unsafe {
rlua::Lua::unsafe_new_with_flags(
StdLib::ALL_NO_DEBUG,
InitFlags::DEFAULT - InitFlags::REMOVE_LOADLIB,
)
.context(|ctx| ctx.load(&buffer).exec())
.unwrap()
};
lua.context(|ctx| -> Result<()> {
let _g = ctx.globals();
_g.set("argv", args)?;
ctx.load(&script).exec()?;
Ok(())
})
.unwrap();
Ok(())
}

0 comments on commit ddc657c

Please sign in to comment.