Commit Graph

13 Commits

Author SHA1 Message Date
staphen 7df7b35123 Clean up warnings and debugger errors related to the Lua console 2023-11-05 11:50:41 +00:00
Gleb Mazovetskiy cec1f1f37c Lua: Implement sandbox
1. Every script runs in its own sandbox.
2. `Events` is the only global shared state.
3. `os` datetime functions are now available.
2023-11-04 21:47:56 +00:00
Gleb Mazovetskiy 8bffbedcb4 Migrate some debug.cpp commands to Lua
Introduces a new `devilutionx.dev` Lua module, automatically loaded in
the console prelude.

Arguments and basic help are shown in autocompletion.
2023-11-04 20:28:27 +00:00
Gleb Mazovetskiy 03893ea27a Lua: Add inspect package
Adds `inspect` from https://github.com/kikito/inspect.lua
This will be part of the console prelude.
2023-11-03 08:59:10 +00:00
Gleb Mazovetskiy 3812d63178 Lua: Fix audio module registration 2023-11-02 17:20:32 +00:00
Gleb Mazovetskiy dbfa204944 Lua: Set warn function
Previously, warnings went nowhere.
2023-11-02 15:16:31 +01:00
Anders Jenbo 4fe90f7b74 Add audio functionality to Lua 2023-11-02 14:34:24 +01:00
Anders Jenbo 8f2990d1e7 Expose engine version to Lua 2023-11-02 14:34:24 +01:00
Gleb Mazovetskiy 5d9d5c6872 Lua: require supports loads from assets
Implements a `require` function that supports built-in modules like so:

```lua
local log = require('devilutionx.log')
```

It falls back to reading from assets, so this loads `lua/user.lua`:

```lua
local user = require('lua.user')
```

The bytecode for the asset scripts is cached, in case we want to later
support multiple isolated environments.

There may be a simpler or better way to do this.

It's good enough for now until someone more knowledgeable
about Lua comes along.
2023-11-02 02:24:06 +00:00
Gleb Mazovetskiy cc0d2e2caf lua.cpp: Use backslash directory separator
Paths going into `FindAsset` are expected to use backslashes
2023-11-01 21:50:30 +00:00
Gleb Mazovetskiy 165f95e38f Require lua/init.lua to succeed
Previously we failed silently if something went wrong.
2023-11-01 21:50:30 +00:00
Gleb Mazovetskiy 3ea4996367 Add a basic Quake-style console
Enabled only in Debug mode.

Runs Lua similar to the `lua` CLI.
Supports multiline input with Shift+Enter.

Missing features:
1. Scrollback.
2. Input history on up/down.

Open with backtick, close with Esc.
2023-10-31 23:19:56 +00:00
Gleb Mazovetskiy de6eac137b Split up lua bindings a bit
```lua
local render = devilutionx.render

local function drawGreet ()
  render.string("Hello from " .. _VERSION, 10, 40)
end
Events.OnGameDrawComplete.Add(drawGreet)
```
2023-10-26 03:48:56 +01:00