Package dan200.computercraft.api.lua
Class LuaValues
java.lang.Object
dan200.computercraft.api.lua.LuaValues
Various utility functions for operating with Lua values.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic LuaException
badArgument
(int index, String expected, String actual) Construct a "bad argument" exception, from an expected and actual type.static LuaException
badArgumentOf
(IArguments arguments, int index, String expected) Construct a "bad argument" exception, from anIArguments
argument and an expected type.static LuaException
Construct a field exception, from an expected and actual type.static LuaException
badTableItem
(int index, String expected, String actual) Construct a table item exception, from an expected and actual type.static <T extends Enum<T>>
TEnsure a string is a valid enum value.static double
checkFinite
(int index, double value) Ensure a numeric argument is finite (i.e.static Number
checkFiniteNum
(int index, Number value) Ensure a numeric argument is finite (i.e.static ByteBuffer
Encode a Lua string into a read-onlyByteBuffer
.static String
getNumericType
(double value) Returns a more detailed representation of this number's type.static String
Get a string representation of the given value's type.
-
Method Details
-
encode
Encode a Lua string into a read-onlyByteBuffer
.- Parameters:
string
- The string to encode.- Returns:
- The encoded string.
-
getNumericType
Returns a more detailed representation of this number's type. If this is finite, it will just return "number", otherwise it returns whether it is infinite or NaN.- Parameters:
value
- The value to extract the type for.- Returns:
- This value's numeric type.
-
getType
Get a string representation of the given value's type.- Parameters:
value
- The value whose type we are trying to compute.- Returns:
- A string representation of the given value's type, in a similar format to that provided by Lua's
type
function.
-
badArgumentOf
Construct a "bad argument" exception, from anIArguments
argument and an expected type.- Parameters:
arguments
- The current arguments.index
- The argument number, starting from 0.expected
- The expected type for this argument.- Returns:
- The constructed exception, which should be thrown immediately.
-
badArgument
Construct a "bad argument" exception, from an expected and actual type.- Parameters:
index
- The argument number, starting from 0.expected
- The expected type for this argument.actual
- The provided type for this argument.- Returns:
- The constructed exception, which should be thrown immediately.
-
badTableItem
Construct a table item exception, from an expected and actual type.- Parameters:
index
- The index into the table, starting from 1.expected
- The expected type for this table item.actual
- The provided type for this table item.- Returns:
- The constructed exception, which should be thrown immediately.
-
badField
Construct a field exception, from an expected and actual type.- Parameters:
key
- The name of the field.expected
- The expected type for this table item.actual
- The provided type for this table item.- Returns:
- The constructed exception, which should be thrown immediately.
-
checkFiniteNum
Ensure a numeric argument is finite (i.e. not infinite orDouble.NaN
.- Parameters:
index
- The argument index to check.value
- The value to check.- Returns:
- The input
value
. - Throws:
LuaException
- If this is not a finite number.
-
checkFinite
Ensure a numeric argument is finite (i.e. not infinite orDouble.NaN
.- Parameters:
index
- The argument index to check.value
- The value to check.- Returns:
- The input
value
. - Throws:
LuaException
- If this is not a finite number.
-
checkEnum
public static <T extends Enum<T>> T checkEnum(int index, Class<T> klass, String value) throws LuaException Ensure a string is a valid enum value.- Type Parameters:
T
- The type of enum we are extracting.- Parameters:
index
- The argument index to check.klass
- The class of the enum instance.value
- The value to extract.- Returns:
- The parsed enum value.
- Throws:
LuaException
- If this is not a known enum value.
-