unexist.dev

Changeset 183:78d09ecd21d1

Re-organized files
author unexist <christoph@unexist.dev>
date Fri, 17 Jul 2020 14:26:20 +0200
parents 3a9d58d21117
children 88290bddc989
files rubtle-lib/src/debug.rs rubtle-lib/src/error.rs rubtle-lib/src/lib.rs rubtle-lib/src/result.rs rubtle-lib/src/types.rs rubtle-lib/src/util.rs
diffstat 6 files changed, 106 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rubtle-lib/src/debug.rs	Fri Jul 17 14:26:20 2020 +0200
@@ -0,0 +1,33 @@
+///
+/// @package Rubtle-Lib
+///
+/// @file Debug functions
+/// @copyright 2020 Christoph Kappel <unexist@subforge.org>
+/// @version $Id$
+///
+/// This program can be distributed under the terms of the GNU GPLv2.
+/// See the file LICENSE for details.
+//
+use std::slice;
+
+use cesu8::from_cesu8;
+
+pub fn debug_stack(ctx: *mut ffi::duk_context, filename: &str, lineno: u32) {
+    unsafe {
+        ffi::duk_push_context_dump(ctx);
+
+        let mut len: ffi::duk_size_t = 0;
+        let data = ffi::duk_safe_to_lstring(ctx, -1, &mut len);
+
+        if !data.is_null() {
+            let bytes = slice::from_raw_parts(data as *const u8, len as usize);
+
+            match from_cesu8(bytes) {
+                Ok(string) => println!("\n{}@{}: {}", filename, lineno, string),
+                Err(_) => unreachable!(),
+            }
+        }
+
+        ffi::duk_pop(ctx);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rubtle-lib/src/error.rs	Fri Jul 17 14:26:20 2020 +0200
@@ -0,0 +1,39 @@
+///
+/// @package Rubtle-Lib
+///
+/// @file Error functions
+/// @copyright 2020 Christoph Kappel <unexist@subforge.org>
+/// @version $Id$
+///
+/// This program can be distributed under the terms of the GNU GPLv2.
+/// See the file LICENSE for details.
+//
+
+use std::fmt;
+use std::error::Error as StdError;
+
+#[derive(Debug)]
+pub struct Error {
+    pub details: String,
+}
+
+impl Error {
+    #[allow(dead_code)]
+    fn new(details: &str) -> Error {
+        Error {
+            details: details.to_string()
+        }
+    }
+}
+
+impl fmt::Display for Error {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "{}", self.details)
+    }
+}
+
+impl StdError for Error {
+    fn description(&self) -> &str {
+        &self.details
+    }
+}
\ No newline at end of file
--- a/rubtle-lib/src/lib.rs	Fri Jul 17 14:21:16 2020 +0200
+++ b/rubtle-lib/src/lib.rs	Fri Jul 17 14:26:20 2020 +0200
@@ -17,11 +17,14 @@
 mod rubtle;
 mod value;
 mod invocation;
-mod result;
+mod error;
+mod types;
+mod debug;
 
 #[cfg(test)] mod tests;
 
 pub use rubtle::Rubtle;
 pub use value::Value;
 pub use invocation::Invocation;
-pub use result::Result;
+pub use error::Error;
+pub use types::{Callback, Result};
\ No newline at end of file
--- a/rubtle-lib/src/result.rs	Fri Jul 17 14:21:16 2020 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-///
-/// @package Rubtle-Lib
-///
-/// @file Error functions
-/// @copyright 2020 Christoph Kappel <unexist@subforge.org>
-/// @version $Id$
-///
-/// This program can be distributed under the terms of the GNU GPLv2.
-/// See the file LICENSE for details.
-//
-
-use std::{fmt, result};
-use std::error::Error as StdError;
-
-pub type Result<T> = result::Result<T, Error>;
-
-#[derive(Debug)]
-pub struct Error {
-    pub details: String,
-}
-
-impl Error {
-    fn new(details: &str) -> Error {
-        Error {
-            details: details.to_string()
-        }
-    }
-}
-
-impl fmt::Display for Error {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "{}", self.details)
-    }
-}
-
-impl StdError for Error {
-    fn description(&self) -> &str {
-        &self.details
-    }
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rubtle-lib/src/types.rs	Fri Jul 17 14:26:20 2020 +0200
@@ -0,0 +1,19 @@
+
+///
+/// @package Rubtle-Lib
+///
+/// @file Types
+/// @copyright 2020 Christoph Kappel <unexist@subforge.org>
+/// @version $Id$
+///
+/// This program can be distributed under the terms of the GNU GPLv2.
+/// See the file LICENSE for details.
+//
+
+use std::result;
+
+use crate::{Error, Invocation, Value};
+
+pub type Result<T> = result::Result<T, Error>;
+
+pub type Callback = Box<dyn Fn(Invocation) -> Result<Value>>;
\ No newline at end of file
--- a/rubtle-lib/src/util.rs	Fri Jul 17 14:21:16 2020 +0200
+++ b/rubtle-lib/src/util.rs	Fri Jul 17 14:26:20 2020 +0200
@@ -27,4 +27,14 @@
 #[allow(unused_macros)]
 macro_rules! hidden_i8str {
     ($($b:expr),*) => (i8str!(-1, $($b as i8),*))
+}
+
+#[allow(unused_macros)]
+macro_rules! debug_stack {
+    ($ctx:expr) => (debug_stack($ctx, file!(), line!()))
+}
+
+#[allow(unused_macros)]
+macro_rules! debug_println {
+    ($($arg:tt)*) => (println!("{}@{}: {}", file!(), line!(), $($arg)*))
 }
\ No newline at end of file