From efe0dc42bd8fcf956240afcac6ef626db367d81e Mon Sep 17 00:00:00 2001 From: James Roseborough Date: Sat, 6 Jul 2013 15:18:39 +0000 Subject: [PATCH] Let LuaValue.checkfunction() return a LuaFunction --- src/core/org/luaj/vm2/LuaFunction.java | 2 +- src/core/org/luaj/vm2/LuaValue.java | 14 ++++++-------- src/core/org/luaj/vm2/Varargs.java | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/core/org/luaj/vm2/LuaFunction.java b/src/core/org/luaj/vm2/LuaFunction.java index e3dc9b96..0f7c01cc 100644 --- a/src/core/org/luaj/vm2/LuaFunction.java +++ b/src/core/org/luaj/vm2/LuaFunction.java @@ -50,7 +50,7 @@ public class LuaFunction extends LuaValue { return true; } - public LuaValue checkfunction() { + public LuaFunction checkfunction() { return this; } diff --git a/src/core/org/luaj/vm2/LuaValue.java b/src/core/org/luaj/vm2/LuaValue.java index 13164df5..648d756a 100644 --- a/src/core/org/luaj/vm2/LuaValue.java +++ b/src/core/org/luaj/vm2/LuaValue.java @@ -650,8 +650,7 @@ public class LuaValue extends Varargs { /** Check that optional argument is a function and return as {@link LuaFunction} *

* A {@link LuaFunction} may either be a Java function that implements - * functionality directly in Java, - * or a {@link LuaClosure} + * functionality directly in Java, or a {@link LuaClosure} * which is a {@link LuaFunction} that executes lua bytecode. * @param defval {@link LuaFunction} to return if {@code this} is nil or none * @return {@code this} cast to {@link LuaFunction} if a function, @@ -862,15 +861,14 @@ public class LuaValue extends Varargs { /** Check that the value is a function , or throw {@link LuaError} if not *

- * A function is considered anything whose {@link type()} returns {@link TFUNCTION}. - * In practice it will be either a built-in Java function, typically deriving from - * {@link LuaFunction} or a {@link LuaClosure} which represents lua source compiled - * into lua bytecode. - * @return {@code this} if if a lua function or closure + * A {@link LuaFunction} may either be a Java function that implements + * functionality directly in Java, or a {@link LuaClosure} + * which is a {@link LuaFunction} that executes lua bytecode. + * @return {@code this} if it is a lua function or closure * @throws LuaError if not a function * @see #checkclosure() */ - public LuaValue checkfunction() { argerror("function"); return null; } + public LuaFunction checkfunction() { argerror("function"); return null; } /** Check that the value is a Globals instance, or throw {@link LuaError} if not diff --git a/src/core/org/luaj/vm2/Varargs.java b/src/core/org/luaj/vm2/Varargs.java index a17d12ac..437b8625 100644 --- a/src/core/org/luaj/vm2/Varargs.java +++ b/src/core/org/luaj/vm2/Varargs.java @@ -298,7 +298,7 @@ public abstract class Varargs { * @return LuaValue that can be called if argument i is lua function or closure * @exception LuaError if the argument is not a lua function or closure * */ - public LuaValue checkfunction(int i) { return arg(i).checkfunction(); } + public LuaFunction checkfunction(int i) { return arg(i).checkfunction(); } /** Return argument i as a java int value, discarding any fractional part, or throw an error if not a number. * @param i the index of the argument to test, 1 is the first argument