Skip to content

Support generating luadoc comments in zig build system #94

@VisenDev

Description

@VisenDev

(Note: I discussed this idea a few months ago in the ziglua discord, however, my original idea didn't end up working out because comptime globally mutable data had been removed from zig. )

It would be nice if ziglua could expose some functionality to the zig build system which would generate luadoc comments from zig source files (or specific zig declarations).

Basic Example:

src/api.zig

pub const Bar = struct {
   bip: usize,
   bap: bool,
};

pub fn foo(b: Bar, c: f32) ?Bar {
    //do something
}

// fn foo is later registered to lua using `autoPushFunction`

build.zig

const luadocs = try ziglua.deriveLuadocs(@import("src/api.zig"));
try ziglua.appendLuadocs(b.path("data/lua/main.lua"));

data/lua/main.lua (after zig build has been run)

--normal lua code
function doSomething() 
     local c = {['bip'] = 1, ['bap'] = false}
     local foo_result = foo(c, 1.5)
     return foo_result;
end


--ZIGLUA LUADOC BEGIN

---@class Bar
---@field bip integer
---@field bap boolean

---@return Bar|nil
---@param b Bar
---@param c number
---function foo

--ZIGLUA LUADOC END

Implementation details would adjust from here. However, this capability, combined with #93, would make lua almost as nice to use as a statically-typed compiled language (because we could now check at compile time whether our lua code is correct and whether it interfaces with our zig functions and types correctly or not)

We could also explore using lua's abstract syntax tree to place doc comments inline in the file - rather than just placing them all in a big blob at the beginning/end. (This would be helpful for function documentation). See lparser.h and luaY_parser

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions