kyren / piccolo

An experimental stackless Lua VM implemented in pure Rust
Creative Commons Zero v1.0 Universal
1.68k stars 63 forks source link

Partially add `string` methods #17

Closed g-plane closed 5 years ago

g-plane commented 5 years ago

I have only added two functions -- len and byte.

Addition: When I was trying adding more functions (not the len and byte function in this PR), I have encountered some issues about lifetime when using String::new, possibly due to my limitation of Rust knowledge.

[0] % cargo check
    Checking luster v0.1.0 (/mnt/working/Programming/Rust/luster)
error[E0477]: the type `[closure@src/stdlib/string.rs:12:41: 26:14 mc:&gc_arena::context::MutationContext<'gc, '_>]` does not fulfill the required lifetime
  --> src/stdlib/string.rs:12:13
   |
12 |             Callback::new_immediate(mc, |args| {
   |             ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: type must satisfy the static lifetime

error[E0621]: explicit lifetime required in the type of `mc`
  --> src/stdlib/string.rs:12:13
   |
5  | pub fn load_string<'gc>(mc: MutationContext<'gc, '_>, _: Root<'gc>, env: Table<'gc>) {
   |                             ------------------------ help: add explicit lifetime `'static` to the type of `mc`: `gc_arena::context::MutationContext<'gc, 'static>`
...
12 |             Callback::new_immediate(mc, |args| {
   |             ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required

error: aborting due to 2 previous errors

Some errors occurred: E0477, E0621.
For more information about an error, try `rustc --explain E0477`.
error: Could not compile `luster`.

To learn more, run the command again with --verbose.
OmnipotentEntity commented 5 years ago

Do you have a gist of the code that errors?