forked from mitchellh/go-mruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
42 lines (36 loc) · 1.07 KB
/
context.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
package mruby
// #include "gomruby.h"
import "C"
// CompileContext represents a context for code compilation.
//
// CompileContexts keep track of things such as filenames, line numbers,
// as well as some settings for how to parse and execute code.
type CompileContext struct {
ctx *C.mrbc_context
filename string
mrb *Mrb
}
func NewCompileContext(m *Mrb) *CompileContext {
return &CompileContext{
ctx: C.mrbc_context_new(m.state),
mrb: m,
}
}
// Closes the context, freeing any resources associated with it.
//
// This is safe to call once the context has been used for parsing/loading
// any Ruby code.
func (c *CompileContext) Close() {
C.mrbc_context_free(c.mrb.state, c.ctx)
}
// Filename returns the filename associated with this context.
func (c *CompileContext) Filename() string {
return C.GoString(c.ctx.filename)
}
// SetFilename sets the filename associated with this compilation context.
//
// Code parsed under this context will be from this file.
func (c *CompileContext) SetFilename(f string) {
c.filename = f
c.ctx.filename = C.CString(c.filename)
}