Skip to content
New issue

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

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

Already on GitHub? # to your account

Idea: generating annotations #1537

Open
hfn92 opened this issue Oct 8, 2023 · 1 comment
Open

Idea: generating annotations #1537

hfn92 opened this issue Oct 8, 2023 · 1 comment

Comments

@hfn92
Copy link

hfn92 commented Oct 8, 2023

I was wondering if it's possible or reasonable for sol2 to generate lua annotations.

For example when defining a type like this:

  lua.new_usertype<Vec2f>("Vec2f",
                          sol::call_constructor, sol::constructors<Vec2f(), Vec2f(float), Vec2f(float, float)>(),
                          "x", &Vec2f::x,
                          "y", &Vec2f::y);

One could generate a lua file like this:

--- @class _Vec2f
local _Vec2f = {}

--- @type number
_Vec2f.x = 0
--- @type number
_Vec2f.y = 0

--- @return _Vec2f
--- @param x? number
--- @param y? number
function Vec2f(x, y) end

After defining all usertypes one would call some function to generate the annotations lua file, which can be pointed to via the workspace.library field in the .luarc.json

This would allow your custom scripting api to have auto-completion and basic type checking when using lua-language-server for example.

@deadlocklogic
Copy link
Contributor

This is out of sol's scope and requires a similar approach to binding generation.
You can however write wrappers around sol registration functions which create a database for each registered usertype/function/variable and populate it with proper metadata: name/type etc...
This approach is used in this project: nbind
And then use this created database to create you own annotation file.
This topic should be treated in a separate fashion IMO.

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

No branches or pull requests

2 participants