MCPcopy Create free account
hub / github.com/anima-engine/mrusty / MrubyImpl

Interface MrubyImpl

src/mruby.rs:299–980  ·  view source on GitHub ↗

A `trait` used on `MrubyType` which implements mruby functionality.

Source from the content-addressed store, hash-verified

297
298/// A `trait` used on `MrubyType` which implements mruby functionality.
299pub trait MrubyImpl {
300 /// Adds a filename to the mruby context.
301 ///
302 /// # Examples
303 ///
304 /// ```
305 /// # use mrusty::Mruby;
306 /// # use mrusty::MrubyError;
307 /// # use mrusty::MrubyImpl;
308 /// let mruby = Mruby::new();
309 /// mruby.filename("script.rb");
310 ///
311 /// let result = mruby.run("1.nope");
312 ///
313 /// match result {
314 /// Err(MrubyError::Runtime(err)) => {
315 /// assert_eq!(err, "script.rb:1: undefined method \'nope\' for 1 (NoMethodError)");
316 /// },
317 /// _ => assert!(false)
318 /// }
319 /// ```
320 #[inline]
321 fn filename(&self, filename: &str);
322
323 /// Runs mruby `script` on a state and context and returns a `Value` in an `Ok`
324 /// or an `Err` containing an mruby `Exception`'s message.
325 ///
326 /// # Examples
327 ///
328 /// ```
329 /// # use mrusty::Mruby;
330 /// # use mrusty::MrubyImpl;
331 /// let mruby = Mruby::new();
332 /// let result = mruby.run("true").unwrap();
333 ///
334 /// assert_eq!(result.to_bool().unwrap(), true);
335 /// ```
336 ///
337 /// ```
338 /// # use mrusty::Mruby;
339 /// # use mrusty::MrubyError;
340 /// # use mrusty::MrubyImpl;
341 /// let mruby = Mruby::new();
342 /// let result = mruby.run("'' + 1");
343 ///
344 /// match result {
345 /// Err(MrubyError::Runtime(err)) => {
346 /// assert_eq!(err, "TypeError: expected String");
347 /// },
348 /// _ => assert!(false)
349 /// }
350 /// ```
351 #[inline]
352 fn run(&self, script: &str) -> Result<Value, MrubyError>;
353
354 /// Runs mruby `script` on a state and context and returns a `Value`. If an mruby Exception is
355 /// raised, mruby will be left to handle it.
356 ///

Callers

nothing calls this directly

Implementers 1

mruby.rssrc/mruby.rs

Calls

no outgoing calls

Tested by

no test coverage detected