Conversation
- Make aliases available to lua - Ensure alieses typed in `gui/launcher` show proper help entry - Enhance help entry with aliased command information - added a simple set of tests
library/LuaApi.cpp
Outdated
| { | ||
| const char *new_alias = luaL_checkstring(L, 1); | ||
| std::vector<std::string> alias; | ||
| split_string(&alias, new_alias, " "); |
There was a problem hiding this comment.
I would prefer to have this function take a list of arguments instead; otherwise there is no way to set up certain aliases, e.g. with spaces in arguments.
It looks like there is a Lua::GetVector() that could work here. It's a more specific function than its name would apply - it reads strings starting at the stack position you give (1) and pushes them all into a vector<string>, but that looks like it should work for our purposes here.
There was a problem hiding this comment.
This change is complete, tests have been updated.
There was a problem hiding this comment.
I was mistaken - on second look, it looks like GetVector takes a table and converts it to a vector, but your code is expecting that.
Have you tested passing a non-table to make sure the code doesn't crash? An error message is fine (and expected).
There was a problem hiding this comment.
I have tested that, and it does crash. I'll take a look and find a way to ensure stability.
There was a problem hiding this comment.
luaL_checktype(L, 1, LUA_TTABLE) before the GetVector call would probably work.
- Adjusting to take in a table / vector for "addAlias"
- Adjusting to take in a table / vector for "addAlias"
|
|
||
| if (!alias.empty()) | ||
| { | ||
| std::string name = alias[0]; |
There was a problem hiding this comment.
I think we should match the AddAlias() signature instead by taking two arguments: name (a string) and arguments (a list of arguments). It looks like you're retrieving the alias name from the first element of the list here, which doesn't match the C++ API.
|
Which PR addresses this point?
I don't see changes to |
|
|
||
| static int internal_listAliases(lua_State *L) | ||
| { | ||
| auto aliases = Core::getInstance().ListAliases(); |
There was a problem hiding this comment.
If we add a Lua::Push override for std::vector, this function could be reduced to Lua::Push(L, Core::getInstance().ListAliases()); return 1;
| @@ -0,0 +1,11 @@ | |||
| -- Simple tests to ensure the alias functions work as expected | |||
| function test.aliases() | |||
| expect.eq(false, dfhack.internal.isAlias("foo")) | |||
There was a problem hiding this comment.
this can actually be flaky since it depends on the current active environment. these function tests allow you to specify a setup/teardown wrapper where you can save the current aliases, clear the alias list for the test, and restore the original aliases afterwards. See the orders plugin tests for an example.
I must have misinterpreted the need to have the alias item show up as part of the helpdb itself, and focused mainly on ensuring that if a user typed an alias, it would show the correct help for them. I will dig into adjusting to make the alias ALSO appear in the helpdb list. |
|
I think that would be required, yeah, otherwise it wouldn't show up as an entry in |
Issue (#3342)
gui/launchershow proper help entry