1 /* $Header: //info.ravenbrook.com/project/jili/version/1.1/code/mnj/lua/LuaFunction.java#1 $
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
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.
28 * Models a Lua function.
29 * Note that whilst the class is public, its constructors are not.
30 * Functions are created by loading Lua chunks (in source or binary
31 * form) or executing Lua code which defines functions (and, for
32 * example, places them in the global table). {@link
33 * Lua#load(InputStream, String) Lua.load} is used
34 * to load a Lua chunk (it returns a <code>LuaFunction</code>),
35 * and {@link Lua#call Lua.call} is used to call a function.
37 public final class LuaFunction
39 private UpVal
[] upval
;
44 * Constructs an instance from a triple of {Proto, upvalues,
45 * environment}. Deliberately not public, See {@link
46 * Lua#load(InputStream, String) Lua.load} for
47 * public construction. All arguments are referenced from the
48 * instance. The <code>upval</code> array must have exactly the same
49 * number of elements as the number of upvalues in <code>proto</code>
50 * (the value of the <code>nups</code> parameter in the
51 * <code>Proto</code> constructor).
53 * @param proto A Proto object.
54 * @param upval Array of upvalues.
55 * @param env The function's environment.
56 * @throws NullPointerException if any arguments are null.
57 * @throws IllegalArgumentsException if upval.length is wrong.
59 LuaFunction(Proto proto
, UpVal
[] upval
, LuaTable env
)
61 if (null == proto
|| null == upval
|| null == env
)
63 throw new NullPointerException();
65 if (upval
.length
!= proto
.nups())
67 throw new IllegalArgumentException();
81 /** Get the Proto object. */
87 /** Getter for environment. */
92 /** Setter for environment. */
93 void setEnv(LuaTable env
)
97 throw new NullPointerException();