Port a single C function from nethack-c/ to its JS equivalent in js/, following Cardinal Rules and porting patterns.
Invoke with /port-function <function_name> to port a specific C function
to JavaScript, or to audit an existing JS port against the C original.
function_name: the C function to port (e.g. dogfood, dochug, m_move)Search nethack-c/src/*.c for the function definition. Read the full
implementation including all local helpers it calls.
grep -rn "^function_name(" nethack-c/src/
Read the entire function body. Note:
rn2, rn1, rnd, d, rnz, rne) and its argumentsflags, context, u. fields)Search js/*.js for the function name or a camelCase equivalent:
grep -rn "function_name\|functionName" js/
docs/LORE.md Cardinal Rule 2)char comparisons become string comparisonsstruct field access becomes object property access0 is falsy, but JS '\0' is truthynode --test test/comparison/sessions.test.js
If specific sessions exercise this function, run them individually:
node test/comparison/session_test_runner.js --verbose <session-path>
If the port required any non-obvious adaptation (C-ism, RNG ordering
subtlety, boolean coercion trap), append a structured entry to
docs/LORE.md under "Recent Findings":
### YYYY-MM-DD - short description
- Context: which function / what session exposed this
- Problem: what was wrong or tricky
- Why: root cause in C semantics
- Fix: what the JS port does differently and why
Summarize:
vault_occupied() returns '\0' which is truthy in JS.mcanmove: Treat as C boolean -- both 0 and false mean immobile.mkobj.newobj() must seed obj.age from current move count.splitobj() / next_ident().