NewStoreWithData creates a new [Store] from engine and associates data with it. Embedders can access data via [Storelike.Data]
(engine *Engine, data interface{})
| 74 | // NewStoreWithData creates a new [Store] from engine and associates data with it. |
| 75 | // Embedders can access data via [Storelike.Data] |
| 76 | func NewStoreWithData(engine *Engine, data interface{}) *Store { |
| 77 | // Allocate an index for this store and allocate some internal data to go with |
| 78 | // the store. |
| 79 | gStoreLock.Lock() |
| 80 | idx := gStoreSlab.allocate() |
| 81 | gStoreMap[idx] = &storeData{engine: engine, data: data} |
| 82 | gStoreLock.Unlock() |
| 83 | |
| 84 | ptr := C.go_store_new(engine.ptr(), C.size_t(idx)) |
| 85 | store := &Store{ |
| 86 | _ptr: ptr, |
| 87 | Engine: engine, |
| 88 | } |
| 89 | runtime.SetFinalizer(store, func(store *Store) { |
| 90 | store.Close() |
| 91 | }) |
| 92 | return store |
| 93 | } |
| 94 | |
| 95 | //export goFinalizeStore |
| 96 | func goFinalizeStore(env unsafe.Pointer) { |
searching dependent graphs…