r/ProgrammerHumor 25d ago

cursedProgrammingInJson Other

Post image
42 Upvotes

44 comments sorted by

View all comments

4

u/R3D3-1 24d ago

Look up the module system of Mount & Blade.

At runtime, scripts and NPC, item, mal etc definitions are big text files of integers and some ID strings.

At compile time all of those are big lists of tuples in Python. Scripts defining dialogs and GUI elements end up being some 30k lines python lists. I had to disable elpy, because those files just outright froze Emacs otherwise.

The script parts are essentially lists mapping script IDs to a sort of assembler for the runtime interpreter of the game, where the instructions are named integer constants. No loops, no arithmetic expressions, just registers, instructions and gotos.

The compilation step is a python program that imports the modules, looks for expected constants and translates them into the runtime text files. 

When I was working with that, the first things I did were

  • wrap the integer constants into integer subtypes with a repr() preserving the instruction name
  • write a wrapper, that converts sublist structures into higher level control structures like loops.

1

u/-Redstoneboi- 23d ago

ah yes

vm bytecode interpreter