Skip to content

Safe API for calling lua functions from rust #5

Closed
@volt0

Description

@volt0

This will require implementing a wrapper structure around the lua state. It should be possible to get an instance of the structure from the global state. Also add the call method, which takes as input a reference to the structure containing the arguments and returns a Result containing the result of the lua function or an error.

For example:

#[derive(ToLuaTable)]
struct User {
    username: String,
    email: String,
    id: u64,
    active: bool,
}

#[derive(FromLuaTable)]
struct CreateUserResult {
    ok: bool,
    id: u64,
}

...

let lua = Lua::global()
let result: CreateUserResult = lua.call("some_module.create_user", &user)?;
if result.ok {
    ...
}
-- some_module.lua
function create_user(username, email, id, active)
    ...
    return true, id
end

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions