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

  • Home
  • SEARCH
  • 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 176843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:56:57+00:00 2026-05-11T13:56:57+00:00

In a C function called from my Lua script, I’m using luaL_ref to store

  • 0

In a C function called from my Lua script, I’m using luaL_ref to store a reference to a function. However, if I then try to use the returned integer index to fetch that function from a different thread which isn’t derived from the same state, all I get back is nil. Here’s the simplest example that seems to demonstrate it:

// Assumes a valid lua_State pL, with a function on top of the stack int nFunctionRef = luaL_ref(pL, LUA_REGISTRYINDEX);  // Create a new state lua_State* pL2 = luaL_newstate(); lua_rawgeti(pL2, LUA_REGISTRYINDEX, nFunctionRef); const char* szType = luaL_typename(pL2, -1); 

I’m finding that szType then contains the value ‘nil’.

My understanding was that the registry was globally shared between all C code, so can anyone explain why this doesn’t work?

If the registry isn’t globally shared in that way, how can I get access to my values like I need to from another script?

  • 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. 2026-05-11T13:56:58+00:00Added an answer on May 11, 2026 at 1:56 pm

    The registry is just a normal table in a Lua state, therefore two unrelated Lua states can’t access the same registry.

    As Kknd says, you’ll have to provide your own mechanism. A common trick is creating an extra state that doesn’t execute any code, it’s used only as a storage. In your case, you’d use that extra state’s registry from your C code. unfortunately, there’s no available method to copy arbitrary values between two states, so you’ll have to unroll any tables.

    copying functions is especially hard, if you’re using the registry for that, you might want to keep track of which state you used to store it, and execute it on the original state, effectively turning it into a cross-state call, instead of moving the function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 201k
  • Answers 201k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer An int already is a bitmask. If you want to… May 12, 2026 at 8:10 pm
  • Editorial Team
    Editorial Team added an answer I copied your markup and jQuery, and it fades in… May 12, 2026 at 8:10 pm
  • Editorial Team
    Editorial Team added an answer You could edit the watch to nowTime.toString() to get readable… May 12, 2026 at 8:10 pm

Related Questions

In a C function called from my Lua script, I'm using luaL_ref to store
I am using Luabind to expose a base class from C++ to Lua from
I have got a C function in a static library, let's call it A,
I want to call a c# function from my javascript function. I have a
Is there any difference in these two? If so, what exactly is the difference?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.