lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I asked this earlier with no response, so I'm thinking my original question was too verbose.  So let me ask more generally:  can anyone provide an example of how to create global userdata objects in C code that are accessible from Lua 5.2 scripts?  I am able to bind my Objective C objects to Lua just fine and can instantiate them from a Lua script, but when I try to instantiate one as a global in C code (ala lua_setglobal) I cannot access it in a  Lua script.  Every attempt to do so results in the following error:

    attempt to index global 'x' (a userdata value)

Where 'x' is the global variable created in my C routine.

In other words,

    y = myLibrary.newObject()
    y:doSomething()


works fine,

but 

    some_global_variable:doSomething()

fails (where some_global_variable is the global variable instantiated directly in a C routine using lua_setglobal).

So, can anyone tell me how this is done?

Thans,

James