Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8298225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:41:29+00:00 2026-06-08T15:41:29+00:00

When embedding Python there is the PyCapsule type to create an object containing a

  • 0

When embedding Python there is the PyCapsule type to create an object containing a C pointer which cannot be modified from Python code, i.e. it’s perfect to pass around stuff that is used only by the C code.

Since my application also supports JavaScript via the SpiderMonkey engine I’m looking for something similar in SpiderMonkey. I know that I can create a custom JSClass with the JSCLASS_HAS_PRIVATE flag but I wonder if there’s another simpler/more lightweight approach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:41:31+00:00Added an answer on June 8, 2026 at 3:41 pm

    There is nothing similar so it is indeed necessary to create a custom class. This is the code I ended up using; it defines a new class “Resource” to store the pointer. While not as pretty as the python way it’s still very straightforward:

    // Define the class and give it some private space for the pointer
    static JSClass resource_class = { "Resource", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_PropertyStub,
        JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub,
        JS_FinalizeStub, JSCLASS_NO_OPTIONAL_MEMBERS };
    
    // Create an object and store the pointer
    JSObject *obj = JS_NewObject(cx, &resource_class, NULL, NULL);
    JS_SetPrivate(cx, obj, MY_POINTER);
    
    // Get the pointer
    void *ptr = JS_GetPrivate(cx, obj);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python module that I import from my C++ code (I'm embedding
I am embedding Python in a C++ library which I am making. I would
I have this code in a C application that's embedding Python (2.7.1): { PyObject
I'm embedding Python into an application. MyClass.name is a property of str type: >>>
When embedding a flash object, is there a way to determine when it's fully
I'm trying to emulate code.InteractiveInterpreter from the embedded Python C API. I'm using PyEval_Evalcode
I'm working on embedding Python in our test suite application. The purpose is to
In a boost python embedding in C++, I have C++ parsing a python (via
I'm embedding Python into a C++ application. I plan to use PyEval_EvalCode to execute
I'm interested in experimenting with embedding Python in my application, to let the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.