Lua

Provides an interface for executing Lua code on the server.

class miney.Lua(luanti: LuantiClient)[source]

Provides an interface for executing Lua code on the Luanti server.

This functionality is dependent on the ‘miney’ mod being installed and running on the server. The mod provides the necessary formspec (‘miney:code_form’) and server-side logic to receive, execute, and return results from Lua code snippets. Without this mod, any attempts to execute code will fail.

dumps(data: Any) str[source]

Convert a Python data type to a string with a Lua data type.

Parameters:

data – Python data to convert to Lua format.

Returns:

Lua formatted string representation of the data.

Raises:

ValueError – If the data type is not supported.

get_node_info(node_name: str = None) Any[source]

Get information about a specific node or all registered nodes.

Parameters:

node_name – The name of the node to get information about. If None, returns information about all registered nodes.

Returns:

The result of the Lua execution with node information.

run(lua_code: str, timeout: int = 10, execution_id: str = None) Any[source]

Execute Lua code on the server and return the result.

Parameters:
  • lua_code – The Lua code to execute.

  • timeout – Maximum wait time in seconds for the result.

  • execution_id – A unique ID for this execution. If None, one will be generated.

Returns:

The result of the Lua execution. Can be None if the script returns no value.

Raises:
  • LuaResultTimeout – When the timeout is reached.

  • LuantiConnectionError – When there is no connection to the server or the required ‘miney’ mod is missing.

  • LuantiPermissionError – When the user lacks the required ‘miney’ privilege on the server.

  • LuaError – When the Lua code execution results in an error on the server.

run_file(filename: str) Any[source]

Loads and runs Lua code from a file.

This is useful for debugging, as Luanti can throw errors with correct line numbers. It’s also easier to use with a Lua capable IDE.

Parameters:

filename – Path to the Lua file to execute.

Returns:

The result of the Lua execution.

send_command(command: str) bool[source]

Sends a chat command prefixed with /miney to the server.

Parameters:

command – The command string to send after ‘/miney’.

Returns:

True if the message was sent, False otherwise.