added GetTrait() and SetTrait() to go code
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hyung-hwan 2024-01-22 01:38:13 +09:00
parent a02c323393
commit 676ba7d746
2 changed files with 29 additions and 1 deletions

View File

@ -67,6 +67,9 @@ type Ext struct {
type BitMask C.hcl_bitmask_t
const TRAIT_LANG_ENABLE_BLOCK BitMask = C.HCL_TRAIT_LANG_ENABLE_BLOCK
const TRAIT_LANG_ENABLE_EOL BitMask = C.HCL_TRAIT_LANG_ENABLE_EOL
var inst_table InstanceTable
func deregister_instance(g *HCL) {
@ -109,6 +112,29 @@ func (hcl *HCL) Close() {
deregister_instance(hcl)
}
func (hcl *HCL) GetTrait() BitMask {
var x C.int
var log_mask BitMask = 0
x = C.hcl_getoption(hcl.c, C.HCL_TRAIT, unsafe.Pointer(&log_mask))
if x <= -1 {
// this must not happen
panic(fmt.Errorf("unable to get log mask - %s", hcl.get_errmsg()))
}
return log_mask
}
func (hcl *HCL) SetTrait(log_mask BitMask) {
var x C.int
x = C.hcl_setoption(hcl.c, C.HCL_TRAIT, unsafe.Pointer(&log_mask))
if x <= -1 {
// this must not happen
panic(fmt.Errorf("unable to set log mask - %s", hcl.get_errmsg()))
}
}
func (hcl *HCL) GetLogMask() BitMask {
var x C.int
var log_mask BitMask = 0
@ -326,7 +352,7 @@ func (hcl *HCL) Execute() error {
func (hcl *HCL) Decode() error {
var x C.int
x = C.hcl_decode(hcl.c, 0, C.hcl_getbclen(hcl.c))
x = C.hcl_decode(hcl.c, C.hcl_getcode(hcl.c), 0, C.hcl_getbclen(hcl.c))
if x <= -1 {
return fmt.Errorf("unable to decode byte codes - %s", hcl.get_errmsg())
}

View File

@ -81,6 +81,8 @@ func main() {
x.SetLogTarget("/dev/stderr")
}
x.SetTrait (x.GetTrait() | hcl.TRAIT_LANG_ENABLE_EOL | hcl.TRAIT_LANG_ENABLE_BLOCK)
err = x.Ignite(1000000)
if err != nil {
fmt.Printf("Error: failed to ignite - %s\n", err.Error())