Commit graph

65 commits

Author SHA1 Message Date
Chris Beck
d7770f5a92 move lua map_location operations to their own file 2014-11-20 15:53:26 -05:00
Chris Beck
fccddbb226 move lua fileops to their own file 2014-11-20 15:37:22 -05:00
Chris Beck
29aaa7e05c fix a bug in lua console implementation
I think that without this, if tab completion is pressed many times
it might cause the lua stack to overflow in some cases.
2014-11-20 15:12:06 -05:00
Chris Beck
e7e0bb57dc keep the old lua print function (to cout) around, as "std_print"
name should change maybe
2014-11-20 15:07:35 -05:00
Chris Beck
dffbd96068 add bindings for map_location functions to the lua kernel base
I mainly want to use this for random map generators, it would be
silly to rewrite this stuff in lua after we already have it in C++
(and unit tested there).
2014-11-19 23:09:37 -05:00
Chris Beck
caeaa6ba67 refactor lua show_dialog
The lua show dialog used to get the video object from resources,
which is not ideal. In this version, lua kernel base internalizes
a pointer to the video object, and show_dialog is bound to a
method of the lua kernel base.

From now on, lua kernels which want to show dialogs need to be
constructed with a pointer to a CVideo, if it is null the lua will
fail with a runtime error.

The application lua kernel is constructed with the video for
game_launcher, and the game lua kernel is modified so that it is
owned by the play controller and not the game events manager, and
held in a boost scoped pointer rather than manually deleted. This
is because the game events manager doesn't have a video object,
also it conceptually seems independent of the lua kernel anyways.

The map generator lua kernels are constructed with NULL, but if a
user configuration dialog is provided (new feature) then when they
try to run it they will update with the mp_create's video pointer.
2014-11-17 17:03:00 -05:00
Chris Beck
59507f3d09 fixup lua error formatting 2014-11-13 20:29:07 -05:00
Chris Beck
2021a42d5b Add lua console
- Add an internal command logger to the lua kernel base, and expose
this.
- Redirect the internal lua `print` to the command logger.
- Add an external logger registration system to lua kernel, in
addition to the internal one.
- Add a lua console dialog which binds to a lua kernel base and
permits to review the contents of the logger and issue new commands,
and report errors.
- Add a hotkey binding to launch the lua console "`"
- Adds tab completion support to the lua console
2014-11-13 11:38:58 -05:00
Chris Beck
aa19f6eecd move gui2 dialog lua functions to the lua kernel base 2014-11-10 21:13:22 -05:00
Chris Beck
1967d52a5d fixup stack discipline with error handling
When a C function terminates, it should not leave bogus elements
on the stack, or the stack can eventually overflow.

This is not as critical for C functions which are called by lua,
because they return an int explaining how many values on the stack
are important. But for C++ facing functions it is very important.
2014-11-10 17:12:55 -05:00
Chris Beck
4134ef3a80 remove comment from dev concerned about a nonissue
read here: http://www.lua.org/manual/5.1/manual.html#lua_CFunction
When the C function returns with "1", all but the top entry are
discarded from the stack. If this function could be called again
and again without ever returning and without ever dumping the stack,
then there could be a stackoverflow, but in this case it's
not possible.
2014-11-10 15:34:14 -05:00
Chris Beck
63399b47e9 move some callbacks (gettext, file ops) to lua kernel base 2014-11-10 15:34:13 -05:00
Chris Beck
76141a0de1 new code for lua protected calls in lua_kernel_base
In initial commit of the new lua kernels, I introduced a problem
by trying to use luaW_pcall and lua_pcall interchangeably via
polymorphism. This doesn't work because their return types don't
match, and it's alot of work to change luaW_pcall syntax. Besides
this there's no reason we can't use the custom error handler
everywhere.

This commits adds protected_call and load_string functions to lua
kernel base. These are an intended replacement for luaW_pcall,
and replace the "run" function. They do better error reporting
and allow to specify an error handler.

The error reporting is very flexible -- by default we select a
an error reporting function associated polymorphically to the lua
kernel, so the in-game lua kernel can send chat messages, and
others can do something else. However an arbitrary handler may
be specified, and exceptions instead of logging may also be
requested.
2014-11-10 15:32:19 -05:00
Chris Beck
ecc714e41e add application lua kernel and game launcher lua wrapper object
The application lua kernel is meant to interpret scripts to drive
the client. Its main features are, it stores a script in its
registry and provides a C++ function to call it with a config
as its argument. Its initialization also creates a "game_launcher"
object, which stands as a limited lua proxy for the C++
game_launcher object.

The game_launcher object is a table, holding a pointer to the
actual game_launcher it represents, and with metamethods to return
version info and the command line arguments. It also holds
callbacks to set the script for the current application lua kernel,
and to call the "play_multiplayer" function of game_launcher.
Currently it is readonly and you cannot write to its fields,
although that may change to allow the target server to be reset,
etc.

Some minor changes that are included in this commit:
- the actual C++ game launcher object provides an accessor to the
command line options.
- the scripting/lua_types.hpp file now has include guards
2014-11-09 20:47:26 -05:00
Chris Beck
4541412ebc add lua_kernel_base as a super class of game_lua_kernel
This class holds some "basic" initialization and methods that we
would want in any lua kernel. It is not pure virtual, it could
be instantiated.
2014-11-09 18:45:14 -05:00