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 LuaExceptionbadArgument(int index, String expected, String actual) Construct a "bad argument" exception, from an expected and actual type.static LuaExceptionbadArgumentOf(IArguments arguments, int index, String expected) Construct a "bad argument" exception, from anIArgumentsargument and an expected type.static LuaExceptionConstruct a field exception, from an expected and actual type.static LuaExceptionbadTableItem(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 doublecheckFinite(int index, double value) Ensure a numeric argument is finite (i.e.static NumbercheckFiniteNum(int index, Number value) Ensure a numeric argument is finite (i.e.static ByteBufferEncode a Lua string into a read-onlyByteBuffer.static StringgetNumericType(double value) Returns a more detailed representation of this number's type.static StringGet 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
typefunction.
-
badArgumentOf
Construct a "bad argument" exception, from anIArgumentsargument 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.
-