Skip to content

Is it possible to define type hints on the fly based on a string in lua? #3369

@ChillerDragon

Description

@ChillerDragon

I have the following lua script

Game:register_rcon("", "i[client_id]s[name]", "", function (client_id, args)
	print(args.client_id) -- integer
	print(args.name) -- string
end)

The string "i[client_id]s[name]" passed to register_rcon determines the shape and types of the callbacks args argument. Right now I typed the callback quite generically

---@param callback fun(client_id: integer, args: table<string, string|integer|nil>) the callback that will be run if a user typed the command name into the remote console
function Game:register_rcon(name, parameters, helptext, callback) end

Can I instead of saying table<string,string|integer|nil> generate a proper table with field names and their types somehow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions