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

Trig functions moved to smlua_math_utils.c for autodoc and macros reused for relevant functions #345

Closed
wants to merge 1 commit into from

Conversation

Multi-Volt
Copy link

@Multi-Volt Multi-Volt commented Oct 2, 2024

This PR is more of a suggestion than a finalized ultra-professional implementation.

As it currently stands sins(), coss(), and atan2s() are all functions exposed to the game's Lua API. Despite this, they are ignored by the autogen for documentation as the macros are declared as explicit lua functions in smlua_functions.c. Normally, for a few functions this would be okay (still not ideal) however, smlua_math_utils.c already features re-definitions (as functions) for the min, max, and sqr macros from math_util.h.

This PR seeks to unify these two clashing ideas by integrating the macros into smlua_math_utils.c by creating functional wrappers for all relevant macros which are friendly with the autodoc generation. This prevents the copying of already written code while also allowing for the documentation to be properly generated for sins(), and coss(). In addition to this, atan2s() was allowed in the autogen script to be included in the function documentation as its already exposed due to its prototype (and thus does not need an explicit declaration in smlua_functions.c).

I would love suggestions for a better implementation and am willing to contribute and fix any issues with this solution.

@Isaac0-dev
Copy link
Collaborator

those functions can be found in manual.lua, which is how IDEs can see the definition of these functions

@Multi-Volt
Copy link
Author

Multi-Volt commented Oct 2, 2024

Updated the PR to remove the redundant documentation in manual.lua. Doing a simple string search it doesn't look like this file is dynamically updated via autogen so this should be fine. The autodoc already generates IDE findable Lua funcs for the updated method.

The benefit of this approach is its inclusion automatically in the markdown files which allows new modders to know these functions exist within the code. Users shouldn't require a specific IDE or need to explore source in order to find all Lua functions. Perhaps in the future it could be advantageous to create an autodoc system for handling manual declarations for the markdown.

If there is a special input type for angles please also let me know if this exists and I'll update the functions accordingly. That way we can have the number Angle annotation as we did previously.

Let me know if there is anything else or if I can add clarification anywhere.

s32 sqr(s32 x) {
return x * x;
s32 (sqr)(s32 x) {
return (s32)sqr(x);
Copy link
Collaborator

@Isaac0-dev Isaac0-dev Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think redefining these is a problem, but if it really is, it'd be better to just expose the functions that are in math_util.c.

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

Successfully merging this pull request may close these issues.

2 participants