Skip to content

Commit

Permalink
toml2json now returns errors to byond (#98)
Browse files Browse the repository at this point in the history
Co-authored-by: ZeWaka <[email protected]>
  • Loading branch information
tralezab and ZeWaka authored Jul 21, 2022
1 parent 76fd17a commit 66260ff
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"rust-analyzer.cargo.target": "i686-pc-windows-gnu"
"rust-analyzer.cargo.target": "i686-pc-windows-msvc"
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ System libraries:

* Other Linux distributions install the appropriate **32-bit development** and **32-bit runtime** packages.

If you want to use the `pc-windows-gnu` or similar other target ABI, do the following:
1. Change the `"rust-analyzer.cargo.target"` setting in `.cargo/config` to `i686-pc-windows-gnu`.
2. Run `git update-index --assume-unchanged .cargo/config`, which will tell git to 'ignore' the changes you made.
3. If you find yourself ever wanting to change back, run `git update-index --no-assume-unchanged .cargo/config`.

## Compiling

The [Cargo] tool handles compilation, as well as automatically downloading and
Expand Down
9 changes: 8 additions & 1 deletion dmsrc/toml.dm
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
#define rustg_read_toml_file(path) json_decode(call(RUST_G, "toml_file_to_json")(path) || "null")
#define rustg_raw_read_toml_file(path) json_decode(call(RUST_G, "toml_file_to_json")(path) || "null")

/proc/rustg_read_toml_file(path)
var/list/output = rustg_raw_read_toml_file(path)
if (output["success"])
return output["content"]
else
CRASH(output["content"])
11 changes: 10 additions & 1 deletion src/toml.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
use crate::error::Result;

byond_fn!(fn toml_file_to_json(path) {
toml_file_to_json_impl(path).ok()
serde_json::to_string(
&match toml_file_to_json_impl(path) {
Ok(value) => serde_json::json!({
"success": true, "content": value
}),
Err(error) => serde_json::json!({
"success": false, "content": error.to_string()
}),
}
).ok()
});

fn toml_file_to_json_impl(path: &str) -> Result<String> {
Expand Down
2 changes: 1 addition & 1 deletion tests/abc-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn are_captures_sorted(matches: CaptureMatches, context: &str) -> Result<(), Str
let mut prev_string = "";
for cap in matches {
let capstring = cap.get(0).unwrap().as_str();
match prev_string.cmp(&capstring) {
match prev_string.cmp(capstring) {
Ordering::Greater => {
return Err(format!("{} is not sorted in {}", &capstring, &context))
}
Expand Down
8 changes: 3 additions & 5 deletions tests/dm/toml.dme
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ var/test_json = @{"
/test/proc/check_toml_file2json()
rustg_file_write(test_toml, "test.toml")

var/toml_output = json_encode(rustg_read_toml_file("test.toml"))
var/test_output = json_encode(json_decode(test_json)) // Double-encode so true becomes 1
var/toml_output = rustg_read_toml_file("test.toml")

// ~= checks for structural equality
if (toml_output != test_output)
CRASH("test:\n[test_toml]\n \nexpected:\n[test_output]\n \nrustg:\n[toml_output]")
if (toml_output != test_json)
CRASH("test:\n[test_toml]\n \nexpected:\n[test_json]\n \nrustg:\n[toml_output]")

0 comments on commit 66260ff

Please sign in to comment.