Module internal

The Bureau of Internal Affairs.

This module groups functions that are for the core’s internal use.

This module in not intended for end-users.

Functions

_sleep(msec) Sleeps for a certain time (milliseconds).
is_restarting() Whether Lua is being restarted.
register_system_callback(slot_name, function) Registers a Lua function at the C side.
request_lua_restart() Requests that the Lua engine be restarted.


Functions

_sleep(msec)
Sleeps for a certain time (milliseconds).

End-users: don’t use this function. You'll never have to. It stops the whole application. Use timers instead.

It may be used to simulate long tasks during testing.

is_restarting()
Whether Lua is being restarted.

Returns true in the time period between the events core::before-restart and core::after-restart.

register_system_callback(slot_name, function)

Registers a Lua function at the C side.

This is the primary means by which we plug Lua into MC.

For example, on the Lua side we do:

require "internal".register_system_callback("ping", function(...)
  print("ping!", ...)
  return 666
end)

…and on the C side:

if (luaMC_get_system_callback (Lg, "ping")) {
  lua_pushstring (Lg, "whatever");
  lua_pushstring (Lg, "you");
  lua_pushstring (Lg, "want");
  if (luaMC_safe_call (Lg, 3, 1)) {
    printf ("I got %d in return\n", lua_tointeger (Lg, -1));
    lua_pop (Lg, 1);
  }
}
request_lua_restart()

Requests that the Lua engine be restarted.

This should be called from a key handler (i.e., keymap.bind) because the C side checks for the request right after a key press was handled.

Typically it’s installed in core/_bootstrap.lua thus:

keymap.bind('C-x l', function()
  require('internal').request_lua_restart()
end)
generated by LDoc 1.4.3 Last updated 2016-08-23 17:29:40