Values

class mehtap.values.Variable(value: LuaValue, constant: bool = False, to_be_closed: bool = False)

Bases: object

Tuple of a Lua value and its properties describing a local variable.

Parameters:
value: LuaValue

The value of the variable.

constant: bool

Whether the local is a constant.

to_be_closed: bool

Whether the local is a to-be-closed variable.

class mehtap.values.LuaValue

Bases: ABC

Base class that all Lua values inherit from.

get_metatable() LuaNilType | LuaTable
Returns:

The value’s metatable if it exists, or LuaNil if not.

Return type:

LuaNilType | LuaTable

has_metavalue(name: LuaString) bool
Parameters:

name (LuaString) – The name of the metavalue to check for.

Returns:

Whether the value has a metavalue with this key.

Return type:

bool

get_metavalue(name: LuaString) LuaValue | None
Parameters:

name (LuaString) – The name of the metavalue to get.

Returns:

The metavalue, or None if the value doesn’t have a metavalue with the given name.

Return type:

LuaValue | None

set_metatable(value: LuaTable)

Set the value’s metatable if the value can have one.

Raises:

NotImplementedError – if the value can’t have a metatable

Parameters:

value (LuaTable)

remove_metatable()

Removes the value’s metatable if the value can have one.

Does nothing if the value can’t have a metatable

mehtap.values.LuaNil = LuaNil

Value that is different from all other LuaValues.

Represents the value of the nil basic type in Lua. Sole object of the LuaNilType class.

class mehtap.values.LuaBool(true: bool)

Bases: LuaValue

Class representing values of the boolean basic type in Lua.

Parameters:

true (bool)

true: bool

Whether this value is true or false.

class mehtap.values.LuaNumberType(value)

Bases: Enum

Enumeration of the types of numbers in Lua.

INTEGER = 1

Number type that represents 64-bit signed integers.

FLOAT = 2

Number type that represents double-precision floating point numbers.

class mehtap.values.LuaNumber(value: int | float, type: LuaNumberType | None = None)

Bases: LuaValue

Class representing values of the number basic type in Lua.

Parameters:
  • value (int | float) – The underlying value of this number value.

  • type (LuaNumberType | None) – The type of this number value. If provided, must match the type of value.

value: int | float

The underlying value of this number value.

type: LuaNumberType | None

The type of this number value.

class mehtap.values.LuaString(content: bytes)

Bases: LuaValue

Class representing values of the string basic type in Lua.

Parameters:

content (bytes)

content: bytes

Sequence of the bytes of the string.

class mehtap.values.LuaObject

Bases: LuaValue, ABC

Base class that Lua objects inherit from.

Tables, functions, threads and (full) userdata values are objects. See Lua 5.4 Reference Manual, Section 2.1.

class mehtap.values.LuaCallableABC

Bases: ABC

Abstract base class for objects that can be called.

If a type that is not a subclass of this class is attempted to be called in execution, a LuaError will be raised.

abstract rawcall(args: Multires, scope: Scope | None, *, modify_tb: bool = True) list[LuaValue]

Call this value.

Parameters:
  • args (Multires) – Arguments to pass.

  • scope (Scope | None) – The scope of the caller.

  • modify_tb (bool) – Whether to add an entry to the tracebacks of errors.

Returns:

the list of LuaValue objects that the callable returns

Return type:

list[LuaValue]

class mehtap.values.LuaFunction(param_names: list[LuaString], variadic: bool, parent_scope: Scope | None, block: Block | Callable, gets_scope: bool = False, name: str | None = None, min_req: int | None = None, signature: str | None = None)

Bases: LuaObject, LuaCallableABC

Class representing values of the function basic type in Lua.

Parameters:
  • param_names (list[LuaString])

  • variadic (bool)

  • parent_scope (Scope | None)

  • block (Block | Callable)

  • gets_scope (bool)

  • name (str | None)

  • min_req (int | None)

  • signature (str | None)

param_names: list[LuaString]

The names of the parameters of the function.

Used when binding given arguments to the block scope when calling the function or when pretty-displaying the function.

variadic: bool

Whether the function is a variadic function.

That is, a function that accepts a variable number of arguments, binding the excess arguments to the expression “...”.

parent_scope: Scope | None

The scope the function was defined in.

The function can access any of these values as upvalues. Not applicable for functions defined from Python.

block: Block | Callable

The code that the function executes.

If of type Block, the function is implemented in Lua. If of type Callable, the function is implemented in Python.

The call() method should be used to call the function.

gets_scope: bool

Whether the function receives the scope as its first argument.

Only applicable for functions implemented in Python.

name: str | None

The name of the function.

min_req: int | None

The minimum number of required arguments.

Only applicable for functions implemented in Python. Only used for pretty-displaying the function.

signature: str | None

The signature of the function.

Only used for pretty-displaying the function.

rawcall(args: Multires, scope: Scope | None, *, modify_tb: bool = True) list[LuaValue]

Call the function.

Parameters:
  • args (Multires) – The arguments to pass to the function.

  • scope (Scope | None) – The scope of the caller.

  • modify_tb (bool) – Whether to add self to the traceback of exceptions. If the caller is handling traceback, should be set to False, otherwise should be set to True.

Returns:

A multires list of the return values of the function.

Return type:

list[LuaValue]

The number of arguments will be suitably adjusted to the number of the function’s arguments according to the rules on adjustment of Lua. Can contain multires expressions.

class mehtap.values.LuaUserdata

Bases: LuaObject

Class representing values of the userdata basic type in Lua.

Users can define their own userdata types by subclassing this class. An example of a subclass of this class is LuaFile.

class mehtap.values.LuaThread

Bases: LuaObject

Class representing values of the thread basic type in Lua.

class mehtap.values.LuaIndexableABC

Bases: LuaValue, ABC

Abstract base class for objects that can be indexed.

If a type that is not a subclass of this class is attempted to be indexed in execution, a LuaError will be raised.

abstract rawput(key: LuaValue, value: LuaValue) None

Put a key-value pair into the object.

Parameters:
Return type:

None

abstract rawget(key: LuaValue) LuaValue

Get the associated value of a key from the object.

Parameters:

key (LuaValue)

Return type:

LuaValue

abstract get_with_fallback(key: LuaValue, fallback: T) LuaValue | T

Get the associated value of a key from the object, or fallback if the key isn’t associated with any value.

Parameters:
Return type:

LuaValue | T

abstract has(key: LuaValue) bool
Returns:

True if the object has a value associated with key, False otherwise.

Parameters:

key (LuaValue)

Return type:

bool

class mehtap.values.LuaTable(map: dict[LuaValue, LuaValue] = NOTHING, metatable: LuaTable | None = None)

Bases: LuaObject, LuaIndexableABC

Class representing values of the table basic type in Lua.

Parameters:
map: dict[LuaValue, LuaValue]

The key-value pairs of the table.

rawput(key: LuaValue, value: LuaValue)

Put a key-value pair into the object.

Parameters:
rawget(key: LuaValue)

Get the associated value of a key from the object.

Parameters:

key (LuaValue)

get_with_fallback(key: LuaValue, fallback: T) LuaValue | T

Get the associated value of a key from the object, or fallback if the key isn’t associated with any value.

Parameters:
Return type:

LuaValue | T

has(key: LuaValue) bool
Returns:

True if the object has a value associated with key, False otherwise.

Parameters:

key (LuaValue)

Return type:

bool

mehtap.values.type_of_lv(a: LuaValue) str
Returns:

The result of type(a) in Lua as a Python str.

Parameters:

a (LuaValue)

Return type:

str

This is not an operation but it is included here for ease of access.