DragosPopse / mani

Lua exporter for odin, made in odin
21 stars 3 forks source link

[Feature Request] Honor default values for exported procedures. #9

Open MineBill opened 4 months ago

MineBill commented 4 months ago

Given this code:

@(LuaExport = {
    Name = "DrawLine",
})
api_debug_draw_line :: proc(from: vec3, to: vec3 = vec3{0, 10, 0}) {
    dbg_draw_line(&EngineInstance.dbg_draw, from, to, color = COLOR_MINT)
}

I should be able to call it from Lua like this:

function()
    DrawLine(make_vec3(0, 0, 0), make_vec3(0, 1, 0))
    -- or
    DrawLine(make_vec3(0, 0, 0)) -- Which should call the `api_debug_draw_line` proc with it's default value
end

Luckily, core:odin/ast already provides us with default values for parameters, so all we need to do is get the source code string and simply append it if it exists when generating the Lua proc wrapper.

(You can take a look at my implementation over here: https://github.com/MineBill/Engin3/commit/b27530c304c374a6868a3d5d21c1da0793aa99d6)

DragosPopse commented 4 months ago

noted, will do. I believe this to be in part related to another planned feature, which is function overloading. its not as straightforward since it needs to be implemented on the C api side, as lua doesnt have the concept of overload