-
-
Notifications
You must be signed in to change notification settings - Fork 453
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
Initial version of new style Lua argument parsing #973
Conversation
Brilliant! So, will we be using |
Yes that is the plan. We need to be careful with converting existing code though, as the behavior of this new stuff may be different in some edge cases. |
cdadfb9
to
734f018
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Almost all of these suggestions are readability/documentation related - I've gone with the approach that if I am having trouble skim-reading something, it should probably be explained in a comment. I hope that's OK.
I've also pointed out some methods that would benefit from guarding (or "short-circuiting"... I'm not really sure what it's called). I think it reduces cognitive load. Let me know what you think about this style.
Also, note that my suggestions to Client/.../CLuaDefs.h
also apply to Server/.../CLuaDefs.h
.
Still to review:
- I have not (yet) checked to make sure you exhaust all types and include the full range of types in all areas of
TypeMatch
/Push
/Pop
. - Deeper read into
CLuaFunctionParser::PopUnsafe
,CLuaFunctionParser::Call
, andCLuaOverloadParser
.
Optional:
- Include a short guide somewhere that tells you what you need to edit when adding a new type. This is probably unnecessary as you cover types in the most general case.
Thanks for the review. I applied some changes to resolve most of it.
I most likely do not cover all of them yet. Adding further types is fairly simple though, so I'd suggest we just add them as we go.
If you have questions, ask me :)
Adding new types is rare, as we usually only introduce new script entities which are all handled already. But as a quick reference for the future:
Details of these operations depend heavily on the type that is to be added. |
} | ||
else | ||
{ | ||
return Call(L, ps..., Pop<typename nth_element_impl<sizeof...(Params), Args...>::type>(L, iIndex)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call recursively calls itself until it has reached the desired number of arguments. In each step we pop the next parameter from the Lua stack and append it to the list of arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then Push the return value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. So if we're trying to call int foo(std::string, float)
we get the following calls:
Call(L);
Call(L, str);
(with str being the string returned from Pop)
Call(L, str, flt)
(flt being the float from Pop)
Push(Func(str, flt));
What's blocking this? |
Some DX rendering stuff gets broken, if you compile MTA with VS 2019. Other than that, this PR looks complete. |
VS2019 on the build server is the big thing. But if @saml1er knows about some rendering issues we should investigate those first before upgrading. Probably some new optimization breaking some wrong code. Could you file an issue for those @saml1er so we can track/investigate them? |
Now that VS2019 is on the build server, and no one created new issues for any DX issues (nor did I observe any bugs in recent nightlies as a result of using vs2019), can we get a fresh look on what's required to proceed with this? Edit: wait for #1135 results |
I'd want to get proper handling for But no real blockers other than that anymore. |
clang complains /mtasa/blue/Build/../Shared/mods/deathmatch/logic/lua/LuaBasic.h:25:14: warning: inline function 'lua::PopPrimitive<std::__1::basic_string<char> >' is not defined
[-Wundefined-inline]
inline T PopPrimitive(lua_State* L, std::size_t& index);
^
../Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h:263:25: note: used here
return lua::PopPrimitive<T>(L, index);
^ |
Any other issue? I want to merge this. |
After reading more about std::string_view, looks like we can easily replace |
607d15b
to
9e4e501
Compare
3dc1497
to
db261d5
Compare
Implement Pop for variant, float, double, unsigned int, bool Fix bug introduced when cleaning up error types
Attempt to fix Linux compilation
Fix map/vector to conform to existing behavior (keep reading on failure, skipping invalid values) Add value notes to errors
Only works for overloads with the same number of parameters
Disallow NaN for float/double
Remove fixme Fix naming convention
Co-Authored-By: Qais Patankar <qaisjp@gmail.com>
Add overload for std::string_view to PopPrimitive
Add missing if constexpr for std::string_view
db261d5
to
8d6f6a1
Compare
Co-Authored-By: Qais Patankar <qaisjp@gmail.com>
🚀 |
Initial stuff for automated Lua argument parsing by applying template magic.
Basically this allows us to directly use C++ functions without needing to handle the argument parsing via argstreams. For example
becomes
which avoids error and reduces the required amount of code massively.
This PR also allows registering functions via the ArgumentParser template (rather than the ArgumentParserWarn template), which causes usage mistakes to be considered a hard error in accordance with #821. As a usage example I mostly converted CLuaCryptDefs to use the new style.
Supported Types:
bool
int
, (todo: ushort, char, uchar)std::string
(todo: SString?)CLuaFunctionRef
(argument only)std::vector<T>
if T is supported (expects a table with consistent value types) (todo: as result)std::unordered_map<K, V>
if K and V are supported (todo: as result)std::optional<T>
if T is supported (expects either a T or nil/none) (todo: as result)std::variant<Ts...>
if all Ts... are supportednullptr
(return type only) to indicatenil
Additionally a lua_State* may be taken as an argument, which will be passed through directly. (We use that in some places to access things based on the running script VM)
Restrictions:
std::unique_ptr
(unlikely to change)No full support for overloads yet. Usingstd::variant
andstd::optional
we have some support for overloading, but a function that expects very different types is not fun to handleNotes:
std::invalid_argument
exception to indicate argument failures inside the functions.Todos: