Giter VIP home page Giter VIP logo

mujs-rs's Introduction

mujs-rs - rust MuJS bindings

Version License Downloads Status

MuJS is a lightweight implementation of the Javascript language in a library. MuJS is licensed under ISC license which is FSF approved and compatible with GPL. MuJS rust bindings are licensed under GPLv3.

Its primary purpose and design is for embedding in other software to add scripting capability to those programs, but it can also be used as an extensible scripting language.

In contrast to other programs that are large and complex, MuJS was designed with a focus on small size, correctness and simplicity. MuJS is written in portable C and implements ECMAScript as specified by ECMA-262.

The interface for binding with native code is designed to be as simple as possible to use, and is similar to Lua.

For more indepth information about MuJS see MuJS Reference Manual.

mujs-rs's People

Contributors

hean01 avatar saethlin avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

saethlin

mujs-rs's Issues

Cant use defaccessor

Hi, I'm trying to use defaccessor to set a getter and setter, any idea if I'm doing something obviously wrong here?

    #[test]
    fn defaccessor_with_closure() {
        let state = ::State::new(::JS_STRICT);
        state.newobject();
        state.newfunction(|js| {
            js.pushnumber(42.0);
        }, "getter", 0);
        state.newfunction(|js| {
            js.pushundefined();
        }, "setter", 1);
        state.defaccessor(-3, "test", ::PropertyAttributes::empty());
        state.getproperty(-1, "test");
    }

backtrace

	thread 'tests::defaccessor_with_closure' panicked at '"TypeError: not a __RustClosure__"', src/lib.rs:243:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:538
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   7: mujs::State::_panic
             at src/lib.rs:243
   8: js_throw
             at mujs/jsrun.c:1221
   9: js_typeerror
             at mujs/jserror.c:102
  10: js_touserdata
             at mujs/jsrun.c:310
  11: mujs::State::_newcfunction_trampoline
             at src/lib.rs:837
  12: jsR_callcfunction
             at mujs/jsrun.c:1031
  13: js_call
             at mujs/jsrun.c:1073
  14: jsR_hasproperty
             at mujs/jsrun.c:522
  15: jsR_getproperty
             at mujs/jsrun.c:534
  16: js_getproperty
             at mujs/jsrun.c:791
  17: mujs::State::getproperty
             at src/lib.rs:726
  18: mujs::tests::defaccessor_with_closure
             at src/lib.rs:2041
  19: <F as test::FnBox<T>>::call_box
             at /checkout/src/libtest/lib.rs:1480
             at /checkout/src/libcore/ops/function.rs:223
             at /checkout/src/libtest/lib.rs:141
  20: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:99

I''m still digging through it but in the call to js_touserdata the object at the top of the stack has a tag of "\001" and the type is userdata.

(gdb) break rust_panic
(...)
(gdb) frame
#7  0x00005555555a2071 in js_touserdata (J=0x7ffff64107c0, idx=-1, tag=0x7ffff640f030 "__RustClosure__")
    at mujs/jsrun.c:310
310		js_typeerror(J, "not a %s(%s)", tag);
(gdb) print v.u.object.type
$30 = JS_CUSERDATA
$34 = {boolean = -163516384, number = 6.9533477290522177e-310, s = {string = 0x7ffff640f020 "\001", length = -163516400}, 
  a = {length = -163516384}, f = {function = 0x7ffff640f020, scope = 0x7ffff640f010}, c = {name = 0x7ffff640f020 "\001", 
    function = 0x7ffff640f010, constructor = 0x0, length = 0}, r = {prog = 0x7ffff640f020, source = 0x7ffff640f010 "\001", 
    flags = 0, last = 0}, iter = {target = 0x7ffff640f020, head = 0x7ffff640f010}, user = {tag = 0x7ffff640f020 "\001", 
    data = 0x7ffff640f010, has = 0x0, put = 0x0, delete = 0x0, finalize = 0x555555571550 <mujs::State::_finalize>}}
(gdb) print v.u.object.u.user.tag
$35 = 0x7ffff640f020 "\001"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.