Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API ref on stack behavior for some Lua functions #115

Closed
nurpax opened this issue Oct 20, 2024 · 2 comments
Closed

API ref on stack behavior for some Lua functions #115

nurpax opened this issue Oct 20, 2024 · 2 comments

Comments

@nurpax
Copy link
Contributor

nurpax commented Oct 20, 2024

Just noting this here before I forget:

Some functions in the Ziglua API have a doc string that forgets to mention that the function pops from the stack. IMO this information is pretty useful when developing bindings.

    /// Does the equivalent to t[`k`] = v where t is the value at the given `index`
    /// and v is the value on the top of the stack
    /// See https://www.lua.org/manual/5.4/manual.html#lua_setfield
    pub fn setField(lua: *Lua, index: i32, k: [:0]const u8) void {
        c.lua_setfield(@ptrCast(lua), index, k.ptr);
    }

In lua docs:

Does the equivalent to t[k] = v, where t is the value at the given index and v is the value on the top of the stack.

This function pops the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event (see [§2.4](https://www.lua.org/manual/5.4/manual.html#2.4)).
    /// Does the equivalent to t[k] = v, where t is the value at the given `index`
    /// v is the value on the top of the stack, and k is the value just below the top
    /// See https://www.lua.org/manual/5.4/manual.html#lua_settable
    pub fn setTable(lua: *Lua, index: i32) void {
        c.lua_settable(@ptrCast(lua), index);
    }

In lua docs:

Does the equivalent to t[k] = v, where t is the value at the given index, v is the value on the top of the stack, and k is the value just below the top.

This function pops both the key and the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event (see [§2.4](https://www.lua.org/manual/5.4/manual.html#2.4)).
    /// Pushes onto the stack the value t[k] where t is the value at the given index and k is the value on the top of the stack
    /// Returns the type of the pushed value
    /// See https://www.lua.org/manual/5.4/manual.html#lua_gettable
    pub fn getTable(lua: *Lua, index: i32) LuaType {

In lua docs:

Pushes onto the stack the value t[k], where t is the value at the given index and k is the value on the top of the stack.

This function pops the key from the stack, pushing the resulting value in its place. As in Lua, this function may trigger a metamethod for the "index" event (see [§2.4](https://www.lua.org/manual/5.4/manual.html#2.4)).

Returns the type of the pushed value.
@nurpax
Copy link
Contributor Author

nurpax commented Oct 20, 2024

Whoops! These have changed significantly since I updated my Ziglua copy. Closing.

@nurpax nurpax closed this as completed Oct 20, 2024
@natecraddock
Copy link
Owner

No worries! I just started improving the docs this week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants