pioneerspacesim/pioneer — pull request #2556 by johnbartholomew (2013-11-19 12:35:36+00:00)
Title: Console autoexec file

To do anything interesting with the Lua console, you first have to import game API modules. That import process is a little annoying, since you have to type in the import statement(s) each time you run the game.

This PR makes the console look for and execute a file (console.lua) from the Pioneer config directory during initialisation. That file is executed in the context of the console, so any global definitions created by that file will be available from the console. Imports are the most obvious use for this, but you can also use it to define helpful functions or values. Errors in console.lua are reported in stderr.txt, but do not cause a redscreen.

An example console.lua file:

Game = import("Game")
Space = import("Space")

function killit(s)
s = s or Game.player:GetCombatTarget()
s:Explode()
end