feat: random generators, frozenset and __hash__/__iter__/__getitem__/__contains__ in Ren'Py python
renpy.random/random get choices, sample, randrange and Random(seed); frozenset, iter and hash are builtins. User classes may define __hash__ (dict keys), __iter__, __getitem__ and __contains__; the converter accepts them instead of rejecting the whole class, which removes the Perk/Skill/Status wall in SaintlyCorruption. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f9eb5c1212
commit
e1c596288e
8 files changed
+165
-18
No files matched your search
@@ -14,7 +14,7 @@ const ir = (name) => JSON.parse(readFileSync(new URL(`./fixtures/${name}.ir.json
|
||||
function runtime() {
|
||||
const store = Object.create(null);
|
||||
const builtins = {
|
||||
any: (xs) => xs.some(Boolean), range: (n) => Array.from({ length: n }, (_, i) => i), max: Math.max, int: Number, str: pyStr, list: (xs = []) => [...xs],
|
||||
any: (xs) => xs.some(Boolean), len: (x) => (x.map ? x.map.size : x.length), range: (n) => Array.from({ length: n }, (_, i) => i), max: Math.max, int: Number, str: pyStr, list: (xs = []) => [...xs],
|
||||
};
|
||||
const scope = {
|
||||
get: (n) => (n in store ? store[n] : builtins[n]),
|
||||
@@ -110,3 +110,14 @@ test("lookups stay lenient outside try, uncaught exceptions are explicit errors"
|
||||
assert.equal(py.strict, 0);
|
||||
void store;
|
||||
});
|
||||
|
||||
test("__hash__, __iter__, __getitem__ and __contains__ work on user classes", () => {
|
||||
const { py, store } = runtime();
|
||||
py.exec(ir("dunders"));
|
||||
assert.equal(store.result_size, 1);
|
||||
assert.equal(store.result_value, 2);
|
||||
assert.deepEqual(store.result_loop, [6, 8, 10]);
|
||||
assert.equal(store.result_item, 4);
|
||||
assert.equal(store.result_in, true);
|
||||
assert.equal(store.result_out, false);
|
||||
});
|
||||
Reference in new issue
Block a user