forked from mitchellh/go-mruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.go
52 lines (41 loc) · 1.32 KB
/
args.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package mruby
import "sync"
// #include "gomruby.h"
import "C"
// ArgSpec defines how many arguments a function should take and
// what kind. Multiple ArgSpecs can be combined using the "|"
// operator.
type ArgSpec C.mrb_aspec
// ArgsAny allows any number of arguments.
func ArgsAny() ArgSpec {
return ArgSpec(C._go_MRB_ARGS_ANY())
}
// ArgsArg says the given number of arguments are required and
// the second number is optional.
func ArgsArg(r, o int) ArgSpec {
return ArgSpec(C._go_MRB_ARGS_ARG(C.int(r), C.int(o)))
}
// ArgsBlock says it takes a block argument.
func ArgsBlock() ArgSpec {
return ArgSpec(C._go_MRB_ARGS_BLOCK())
}
// ArgsNone says it takes no arguments.
func ArgsNone() ArgSpec {
return ArgSpec(C._go_MRB_ARGS_NONE())
}
// ArgsReq says that the given number of arguments are required.
func ArgsReq(n int) ArgSpec {
return ArgSpec(C._go_MRB_ARGS_REQ(C.int(n)))
}
// ArgsOpt says that the given number of arguments are optional.
func ArgsOpt(n int) ArgSpec {
return ArgSpec(C._go_MRB_ARGS_OPT(C.int(n)))
}
// The global accumulator when Mrb.GetArgs is called. There is a
// global lock around this so that the access to it is safe.
var getArgAccumulator []C.mrb_value
var getArgLock = new(sync.Mutex)
//export goGetArgAppend
func goGetArgAppend(v C.mrb_value) {
getArgAccumulator = append(getArgAccumulator, v)
}