lua-users home
lua-l archive

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



Hello Lua enthusiasts :)

I've been making quite light use of lua (from C/C++) on and off for a
couple of years now and I love it to bits :)

There are two things that I always wanted, but have never quite figured
out how to do.  I'm sure they're probably quite easy.  Here's the first;
I'll put the other in a separate mail.

Quite often I'll create a lua_State, and at the same time I'll create
some C structures or C++ objects.  Something along the lines of:

lua_State * lua = luaL_newstate ();
MyThing * thing = new MyThing ();

Semantically, the C++ objects 'belong' to the lua_State.  I have more
than one lua_State in my program, and I'd like each one to carry its
associated C++ structures around with it.  However (and this is the
important bit) I don't want any scripts that the lua_State executes to
be able to access or modify the objects.  The C++ objects should be
invisible to any lua scripts.

What I've always done up to now is to make them global light user data
variables, and give them names that are unlikely to clash with anything
else.

lua_pushlightuserdata (lua, thing);
lua_setglobal (lua, "incredibly_unusual_variable_name");

Later on a C function might called from lua, and by using lua_getglobal
it can get at the C++ object.

The obvious problem with this is that "unlikely to clash" is not good
enough.  The following lua script might get executed:

incredibly_unusual_variable_name = 42

... and then I'd be in trouble.

So my question is:  Is there a more robust way of doing this?  I'd
really like the values to be completely hidden from scripts.


Thanks in advance,
Peter Pimley

__________________________________________________________________________________________________________________________________________
Information contained in this e-mail is intended for the use of the addressee only, and is confidential and may be the subject of Legal Professional Privilege.  Any dissemination, distribution, copying or use of this communication without prior permission of the addressee is strictly prohibited.The views of the author may not necessarily constitute the views of Kuju Entertainment Ltd. Nothing in this email shall bind Kuju Entertainment Ltd in any contract or obligation.

The contents of an attachment to this e-mail may contain software viruses which could damage your own computer system. While Kuju Entertainment has taken every reasonable precaution to minimise this risk, we cannot accept liability for any damage which you sustain as a result of software viruses. You should carry out your own virus checks before opening the attachment.

Kuju Entertainment Ltd trading as Zoe Mode

Registered Office : 185 Park Street, Bankside, London, SE19DY. Company Number : 3481384.Company Registered in England.
__________________________________________________________________________________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
_________________________________________________________________________________________________________________________________________