JPC-RR r11.7
[jpcrr.git] / mnj / lua / LuaUserdata.java
blob10b008d53d83e50c51913e59628106bda6c1160e
1 /* $Header: //info.ravenbrook.com/project/jili/version/1.1/code/mnj/lua/LuaUserdata.java#1 $
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
3 * All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject
11 * to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //Modified 2009-12-27 by Ilari Liusvaara
26 //- Make getUserdata public.
28 package mnj.lua;
30 /**
31 * Models an arbitrary Java reference as a Lua value.
32 * This class provides a facility that is equivalent to the userdata
33 * facility provided by the PUC-Rio implementation. It has two primary
34 * uses: the first is when you wish to store an arbitrary Java reference
35 * in a Lua table; the second is when you wish to create a new Lua type
36 * by defining an opaque object with metamethods. The former is
37 * possible because a <code>LuaUserdata</code> can be stored in tables,
38 * and passed to functions, just like any other Lua value. The latter
39 * is possible because each <code>LuaUserdata</code> supports a
40 * metatable.
42 public final class LuaUserdata
44 private Object userdata;
45 private LuaTable metatable;
46 private LuaTable env;
47 /**
48 * Wraps an arbitrary Java reference. To retrieve the reference that
49 * was wrapped, use {@link Lua#toUserdata}.
50 * @param o The Java reference to wrap.
52 public LuaUserdata(Object o)
54 userdata = o;
57 /**
58 * Getter for userdata.
59 * @return the userdata that was passed to the constructor of this
60 * instance.
62 public Object getUserdata()
64 return userdata;
67 /**
68 * Getter for metatable.
69 * @return the metatable.
71 LuaTable getMetatable()
73 return metatable;
75 /**
76 * Setter for metatable.
77 * @param metatable The metatable.
79 void setMetatable(LuaTable metatable)
81 this.metatable = metatable;
84 /**
85 * Getter for environment.
86 * @return The environment.
88 LuaTable getEnv()
90 return env;
92 /**
93 * Setter for environment.
94 * @param env The environment.
96 void setEnv(LuaTable env)
98 this.env = env;