cadcraft/crates/ui-egui/tests
Books 8166e4a809
AutoLISP: load and run .lsp routines (fixes #758) (#855)
* AutoLISP: load and run .lsp routines (#758)

CADCraft runs AutoLISP routines. `.lsp` files load with APPLOAD, (load)
or by dropping them on the window, and at startup from the support folder
(acad.lsp once per session or per drawing with ACADLSPASDOC, acaddoc.lsp
per drawing, then S::STARTUP; never from a drawing's own folder).
(defun c:NAME …) defines commands, (autoload) defers loading to first
use, and (expression) and !variable work at the command line and at
prompts. docs/autolisp.md lists what is supported.

The interpreter (crates/engine/src/lisp) reads source with its own
stack and evaluates on an explicit-stack machine, so a routine can stop
for input (getpoint, pause in command) and carry on later on one thread,
deep recursion is an error rather than a crash, and long loops run a
slice per frame (Esc stops them). It follows AutoLISP: 32-bit wrapping
integers, dynamic scope, *error*, vl-catch-all-apply, AutoLISP's error
wording. About 200 built-ins cover the language, command (with pause and
commands left open), entity lists (entget/entmake/entmod/entdel/entlast/
entnext/handent, through the DXF reader and writer's groups, exposed by
cadcraft-io and handed to the engine through a hook), ssget with modes
and filters, tables, system variables, get… input with initget, and
units. A routine is one undo step; each drawing has its own symbols.

Also: keywords typed as _KEYWORD match at prompts; TEXT run by a
routine's command takes one line; DIMENSION records carry their
measurement (42); Prompt::raw shows a get… prompt as written; the
interface asks Session::prompting() (a command's or a routine's prompt)
where it asked whether a command runs, so clicks, right-click and Delete
work at a routine's prompts; getcorner and based get… prompts drag a
rubber band.

Tests: the language, errors, startup files, interactive input, hostile
input (lisp/tests.rs); the #648 corpus, 18/18, when CADCRAFT_LISP_CORPUS
points at it (tests/lisp_corpus.rs); drop, frames and canvas clicks in
the app (ui-egui/tests/lisp_files.rs).

* AutoLISP: bound memory, drop nested values iteratively, guard the per-frame tick

- Cons cells drop with a work list over both car and cdr (and function
  bodies), so a list nested a million deep in its car no longer overflows
  the stack when it goes away.
- Memory caps so a runaway routine fails with a LISP error instead of an
  uncatchable out-of-memory abort: at most 5,000,000 live cons cells
  (counted in Value::cons / Drop, checked every step; cells the drawing's
  variables already held at the run's start don't count against it), no
  string a built-in makes longer than 8 MiB (strcat checks before joining,
  printed text is cut), and a 2 GiB per-run budget for new strings,
  printed text and files read.
- Session::lisp_tick runs under catch_unwind, and so does every slice of
  the LISP machine: a panic ends the routine with "internal error", puts
  the drawing back and leaves the session usable.
- Regression tests for each (deep car nesting, nested functions, the cell
  cap, string length and budget, a panicking built-in in a blocking run
  and in a ticked one).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Brandon Thomas <echelon@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 05:33:57 -04:00
..
chrome_geometry.rs Keep the layout tabs inside the status bar (#821) 2026-10-13 04:37:37 -04:00
context_menu.rs Temporary tracking point TT and tracking TK at every point prompt (part of #441) (#445) 2026-10-11 11:23:45 -04:00
context_menus.rs Shortcut menus: command menu while a command runs, selection menu with object edits (part of #512) (#515) 2026-10-11 11:48:12 -04:00
control_cmdline.rs Control channel: headless and app reply alike to cmdline.input, state and app.open (fixes #351) (#352) 2026-10-10 17:32:24 -04:00
control_cmdline_key.rs Control channel: cmdline.key replies like cmdline.input (fixes #360) (#361) 2026-10-10 18:09:26 -04:00
control_methods.rs Control channel: control.methods lists the methods, ping answers (fixes #843) (#852) 2026-10-13 04:37:57 -04:00
dialog_dispatch.rs Print opens a Plot dialog (#160) (#200) 2026-10-11 11:12:34 -04:00
docking_workflows.rs UI.9: integrate shared workspace docking and preserve CAD controls 2026-10-10 13:30:09 -06:00
drafting_spacing.rs Persist SNAPUNIT and GRIDUNIT in DXF (fix #607) (#614) 2026-10-11 14:28:56 -04:00
drawing_recovery.rs Autosave (SAVETIME, SAVEFILEPATH) and Drawing Recovery after a crash (fixes #406) (#416) 2026-10-11 11:18:49 -04:00
file_tab_titles.rs File tabs: cut long drawing names short with an ellipsis (#657) 2026-10-12 03:11:59 -04:00
gpu_faults.rs GPU errors and device loss: keep running, autosave at once, tell the user (#652) 2026-10-11 20:42:45 -04:00
gpu_viewport_stencil.rs Active viewport highlight: selection on the GPU, hover cached apart, kept inside a clipped outline (#770) 2026-10-13 04:34:40 -04:00
hidden_command_line.rs AREA: refuse an open elliptical arc instead of measuring the whole ellipse (#487) (#601) 2026-10-11 14:04:40 -04:00
lisp_files.rs AutoLISP: load and run .lsp routines (fixes #758) (#855) 2026-10-13 05:33:57 -04:00
measure_distance_snapping.rs Fix Measure Distance snapping through layout viewports (#616) 2026-10-11 13:39:39 -04:00
mspace_viewport_view.rs Active viewport highlight: selection on the GPU, hover cached apart, kept inside a clipped outline (#770) 2026-10-13 04:34:40 -04:00
open_bytes.rs Web: File > Open… shows the browser's file picker (fixes #55) (#199) 2026-10-10 14:38:20 -04:00
options_dialog.rs OPTIONS: preferences dialog, JSON form and a user profile that survives restarts (fixes #23) (#531) 2026-10-11 12:34:34 -04:00
options_followups.rs Drafting/plot/UI follow-ups: PolarSnap over isometric snap, MVIEW Restore, plot margins, PNG/SVG pens, PE_URL links, OPTIONS settings (part of #626) (#633) 2026-10-11 20:11:06 -04:00
properties_units.rs Properties palette: numeric fields take feet and inches, show lengths in the drawing's units, and report what they can't read (fixes #849) (#870) 2026-10-13 05:23:59 -04:00
rapid_clicks.rs Canvas: every click places a point while drawing, however fast (fixes #815) (#835) 2026-10-13 04:42:53 -04:00
recent_files.rs Recent files: the Start page and File ▸ Open Recent list the drawings opened last (fixes #858) (#864) 2026-10-13 04:44:44 -04:00
save_version.rs SAVEAS version and binary DXF, default save version (fixes #421) (#431) 2026-10-11 11:19:47 -04:00
shared_controls.rs Make right palette collapse arrow interactive (fix #617) (#640) 2026-10-11 19:53:05 -04:00
shortcut_menus.rs Shortcut menus: command line, drawing and layout tabs, Layers and Properties palettes (fixes #512) (#518) 2026-10-11 12:09:56 -04:00
style_dialogs.rs Add PTYPE as an alias of the Point Style command (#622) (#645) 2026-10-11 19:52:37 -04:00
system_cursor.rs Option to keep the system cursor over the drawing area for magnifiers (#39) (#187) 2026-10-10 14:38:13 -04:00
text_double_click.rs Double-click on text, mtext or an attribute definition starts TEXTEDIT on it (part of #842) (#868) 2026-10-13 04:38:18 -04:00
toolsets_gear.rs Tool Sets: the gear on a category header opens that category's options (#620) 2026-10-11 19:53:19 -04:00
workspace_focus.rs UI: retain shared workspace while merging current main 2026-10-10 18:31:07 -06:00
xref_palette.rs Xrefs: External References palette and XREF (fixes #525) (#533) 2026-10-11 12:11:52 -04:00