pub struct MRubyCompiler2Context { /* private fields */ }Implementations§
Source§impl MRubyCompiler2Context
impl MRubyCompiler2Context
Sourcepub unsafe fn new() -> Self
pub unsafe fn new() -> Self
Creates a new MRubyCompiler2Context
Examples found in repository?
examples/cfunc.rs (line 6)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 unsafe {
6 let mut cxt = MRubyCompiler2Context::new();
7 cxt.compile_to_c_function(
8 "puts \"Hello, mruby-compiler2!\"",
9 "init_test_func",
10 std::path::Path::new("examples/out.c"),
11 )?;
12 }
13 println!("Created examples/out.c");
14 Ok(())
15}More examples
examples/smoke.rs (line 6)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 unsafe {
6 let mut cxt = MRubyCompiler2Context::new();
7 cxt.dump_bytecode("puts \"Hello, mruby-compiler2!\"")?;
8
9 let bin = cxt.compile("puts \"Hello, mruby-compiler2!\"")?;
10
11 let out = std::fs::File::create("examples/out.mrb")?;
12 std::io::Write::write_all(&mut &out, &bin)?;
13
14 println!("Compiled bytecode file: examples/out.mrb, size: {}", bin.len());
15 }
16 Ok(())
17}Sourcepub unsafe fn compile(
&mut self,
code: &str,
) -> Result<Vec<u8>, MRubyCompiler2Error>
pub unsafe fn compile( &mut self, code: &str, ) -> Result<Vec<u8>, MRubyCompiler2Error>
Compiles the given mruby code into mruby bytecode binary
Returns the bytecode as a Vec<u8>
Examples found in repository?
examples/smoke.rs (line 9)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 unsafe {
6 let mut cxt = MRubyCompiler2Context::new();
7 cxt.dump_bytecode("puts \"Hello, mruby-compiler2!\"")?;
8
9 let bin = cxt.compile("puts \"Hello, mruby-compiler2!\"")?;
10
11 let out = std::fs::File::create("examples/out.mrb")?;
12 std::io::Write::write_all(&mut &out, &bin)?;
13
14 println!("Compiled bytecode file: examples/out.mrb, size: {}", bin.len());
15 }
16 Ok(())
17}Sourcepub unsafe fn dump_bytecode(
&mut self,
code: &str,
) -> Result<(), MRubyCompiler2Error>
pub unsafe fn dump_bytecode( &mut self, code: &str, ) -> Result<(), MRubyCompiler2Error>
Dumps the compiled bytecode of the given mruby code to stdout
Examples found in repository?
examples/smoke.rs (line 7)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 unsafe {
6 let mut cxt = MRubyCompiler2Context::new();
7 cxt.dump_bytecode("puts \"Hello, mruby-compiler2!\"")?;
8
9 let bin = cxt.compile("puts \"Hello, mruby-compiler2!\"")?;
10
11 let out = std::fs::File::create("examples/out.mrb")?;
12 std::io::Write::write_all(&mut &out, &bin)?;
13
14 println!("Compiled bytecode file: examples/out.mrb, size: {}", bin.len());
15 }
16 Ok(())
17}Sourcepub unsafe fn compile_to_file(
&mut self,
code: &str,
path: &Path,
) -> Result<(), Box<dyn Error>>
pub unsafe fn compile_to_file( &mut self, code: &str, path: &Path, ) -> Result<(), Box<dyn Error>>
Compiles the given mruby code and writes the bytecode to the specified file path
Sourcepub unsafe fn compile_to_c_function(
&mut self,
code: &str,
initname: &str,
path: &Path,
) -> Result<(), MRubyCompiler2Error>
pub unsafe fn compile_to_c_function( &mut self, code: &str, initname: &str, path: &Path, ) -> Result<(), MRubyCompiler2Error>
Compiles the given mruby code and writes the bytecode as a C function to the specified file path
Examples found in repository?
examples/cfunc.rs (lines 7-11)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 unsafe {
6 let mut cxt = MRubyCompiler2Context::new();
7 cxt.compile_to_c_function(
8 "puts \"Hello, mruby-compiler2!\"",
9 "init_test_func",
10 std::path::Path::new("examples/out.c"),
11 )?;
12 }
13 println!("Created examples/out.c");
14 Ok(())
15}