funcval

package module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2023 License: Apache-2.0 Imports: 3 Imported by: 1

README

funcval

golang runtime funcval extract

Go1.14 Go1.15 Go1.16 Go1.17 Go1.18

extract closure env variable

func Get(fn interface{}) (fv *FuncVal, makefunc int)

package main

import (
	"unsafe"

	"github.com/visualfc/funcval"
)

func main() {
	a := 1
	b := "hello"
	c := 10
	fn := func() {
		println(a, b, c)
	}
	c = 20
	fv, _ := funcval.Get(fn)
	type closure struct {
		funcval.FuncVal
		a int
		b string
		c *int
	}
	env := (*closure)(unsafe.Pointer(fv))
	println(env.a, env.b, *env.c)
}

Documentation

Index

Constants

View Source
const (
	IsSupport = runtime.Compiler != "gopherjs"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FuncVal

type FuncVal struct {
	Fn uintptr
}

func Get

func Get(fn interface{}) (fv *FuncVal, makefunc int)

Get returns function/closure interface *FuncVal and count of make by reflect.MakeFunc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL