Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
how to nest a C function inside a MuJS object

I needed to extend my C app with a scripting language so I tried MuJS, it's written in simple C, but it lacks documentation about specifics. Digging through the code I couldn't figure out how to do this basic task of creating a simple object with a function inside it.

expected result:

myobject: {
    myfn: function () {}
}

I tried this but it resulted in an "uncaught exception".

    js_newobject(J);
    {
        js_newcfunction(J, myfn, "myfn", 2);
        js_setproperty(J, -2, "myfn");
    }
    js_setglobal(J, "myobject");
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

As you mentionned it, MuJS is poorly documented. You must consider switching to a better documented and widely used alternatives such as LuaJIT. Look at an example here .

about 4 years ago · Juan Pablo Isaza Report

0

You're probably doing something else wrong, because the code you wrote should work as expected.

Here's a full example with your code that compiles and runs without errors:

#include <stdio.h>
#include "mujs.h"

void myfn(js_State *J)
{
        printf("Hello, world!\n");
}

int main(int argc, char **argv)
{
        js_State *J = js_newstate(NULL, NULL, 0);

        js_newobject(J);
        js_newcfunction(J, myfn, "myfn", 0);
        js_setproperty(J, -2, "myfn");
        js_setglobal(J, "myobject");

        js_dostring(J, "myobject.myfn()");

        js_freestate(J);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!