add ref for grabbing a function
This commit is contained in:
parent
409aa9c34e
commit
88434a932a
|
|
@ -40,6 +40,7 @@ export const globals = {
|
|||
'var?': function (this: VM, v: string) {
|
||||
return typeof v !== 'string' || this.scope.has(v)
|
||||
},
|
||||
ref: (fn: Function) => fn,
|
||||
|
||||
// type predicates
|
||||
'string?': (v: any) => toValue(v).type === 'string',
|
||||
|
|
|
|||
|
|
@ -77,3 +77,15 @@ describe('introspection', () => {
|
|||
await expect(`describe 'hello'`).toEvaluateTo("#<string: \u001b[32m'hello\u001b[32m'\u001b[0m>", globals)
|
||||
})
|
||||
})
|
||||
|
||||
describe('ref', () => {
|
||||
expect(`rnd = do x: true end; rnd | type`).toEvaluateTo('boolean')
|
||||
expect(`rnd = do x: true end; ref rnd | type`).toEvaluateTo('function')
|
||||
|
||||
expect(`math.random | type`).toEvaluateTo('number')
|
||||
expect(`ref math.random | type`).toEvaluateTo('native')
|
||||
|
||||
expect(`rnd = math.random; rnd | type`).toEvaluateTo('number')
|
||||
expect(`rnd = ref math.random; rnd | type`).toEvaluateTo('number')
|
||||
expect(`rnd = ref math.random; ref rnd | type`).toEvaluateTo('native')
|
||||
})
|
||||
Loading…
Reference in New Issue
Block a user