Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: (push, pop) array methods #49

Merged
merged 3 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/runtime/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
unlinkSync as deleteFileSync,
} from 'fs';
import path from 'path';
import { Runtime } from 'inspector';

export function createGlobalEnv(filename: string): Environment {
const env = new Environment();
Expand Down Expand Up @@ -237,6 +238,24 @@ export function createGlobalEnv(filename: string): Environment {
return MK_NUMBER(keys.properties.size);
}),
)
.set(
'ongera_kumusozo',
MK_NATIVE_FN((args) => {
const obj = args[0] as ObjectVal;
const val = args[1];
const key = obj.properties.size; // get the size of the map
obj.properties.set(key.toString(), val);
return MK_NUMBER(obj.properties.size); // return the new size of arr.
}),
)
.set(
'siba_kumusozo',
MK_NATIVE_FN((args) => {
const obj = args[0] as ObjectVal;
obj.properties.delete((obj.properties.size - 1).toString()); // remove the last element
return MK_NUMBER(obj.properties.size); // return the new size of arr.
}),
)
.set(
'ifite_ikirango',
MK_NATIVE_FN((args) => {
Expand Down
5 changes: 5 additions & 0 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ Support:
- Stop Kin while it's running
- Recursion
- Introduce more native functions

Methods:

- unshift for arrays
- shift for arrays
Loading