Skip to content

Add a Lua server/client console debug tool.#3

Merged
max99x merged 5 commits intomasterfrom
lua-console
Jul 5, 2017
Merged

Add a Lua server/client console debug tool.#3
max99x merged 5 commits intomasterfrom
lua-console

Conversation

@max99x
Copy link
Copy Markdown
Collaborator

@max99x max99x commented Jul 3, 2017

This adds a console to interactively execute arbitrary Lua code on the client or server. It gives full read/write access to the global scope and also conveniently exposes the currently selected entity. The goal is to be able to interactively examine and prod game state during debugging.

Screenshot

@max99x max99x requested a review from lindacai1 July 3, 2017 11:44
@jamiltron jamiltron self-requested a review July 3, 2017 23:12
@jamiltron
Copy link
Copy Markdown
Collaborator

Stonehearth is my favorite repl.

Copy link
Copy Markdown
Collaborator

@lindacai1 lindacai1 left a comment

Choose a reason for hiding this comment

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

Looks good overall

Though I'm not sure this is something we should be exposing to the user, even if it's hidden behind the enable_lua_console_hotkey config option. Seems dangerous to allow them to run arbitrary code without a sandbox. Maybe only enable this in developer builds?

<script type="text/x-handlebars" data-template-name="luaConsoleIcon">
<div id="luaConsoleIcon" title="Lua Console"></div>
</script>
<script type="text/x-handlebars" data-template-name="_toolbar">
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm guessing this isn't used? We should also remove the one in object_browser

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed.

view.focus();
}
} else {
App.debugView.addView(App.StonehearthLuaConsoleView)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

semicolon missing

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

position: absolute;
top: 9px;
left: 655px;
font-family: "Lucida Console", monospace;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add Lucida Console to variables.less and access the font through there? We generally try to avoid using the font strings directly to avoid duplication.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Switched to @debugFontFamily.

-- let executed code set global vars. We could instead compile the expression as a
-- function with an entity argument, but if it's a statement, it won't be able to
-- normally set global vars, so no REPL state.
local saved_entity = rawget(_G, 'e')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel like naming the variable entity is more intuitive than e. e is less verbose though 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I started off with "entity", but after playing with it for a while, it was a pain to type that every time. I considered using something particularly weird like $ and replacing it with some auto-generated variable name in the script before compiling, but that seems worse,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's fair. Lets stick with e then

@lindacai1
Copy link
Copy Markdown
Collaborator

Also, thanks for doing this! This will be super helpful for debugging

@relyss
Copy link
Copy Markdown

relyss commented Jul 5, 2017

Thanks! This is appreciated. RepeatPan did something like this back in the day and it was useful, it helped me to debug some Candyland stuff with his help.
Like Linda I'm also concerned about releasing it to the public (it will get in the build once merged).

@max99x max99x merged commit bc6ee08 into master Jul 5, 2017
@max99x max99x deleted the lua-console branch August 9, 2017 15:31
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.

4 participants