MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / getSpellVM

Function getSpellVM

internal/scripting/spell.go:147–192  ·  view source on GitHub ↗
(scriptId string)

Source from the content-addressed store, hash-verified

145}
146
147func getSpellVM(scriptId string) (*VMWrapper, error) {
148
149 if vmw, ok := spellVMCache[scriptId]; ok {
150 if vmw == nil {
151 return nil, errNoScript
152 }
153 if scriptHotReload {
154 spellData := spells.GetSpell(scriptId)
155 if spellData != nil {
156 if info, err := os.Stat(spellData.GetScriptPath()); err == nil {
157 if info.ModTime().After(vmw.loadedAt) {
158 delete(spellVMCache, scriptId)
159 // fall through to reload
160 } else {
161 return vmw, nil
162 }
163 } else {
164 return vmw, nil
165 }
166 } else {
167 return vmw, nil
168 }
169 } else {
170 return vmw, nil
171 }
172 }
173
174 spellData := spells.GetSpell(scriptId)
175 if spellData == nil {
176 return nil, fmt.Errorf("spell %s not found", scriptId)
177 }
178
179 script := spellData.GetScript()
180 if len(script) == 0 {
181 spellVMCache[scriptId] = nil
182 return nil, errNoScript
183 }
184
185 vmw, err := loadVM(fmt.Sprintf(`spell-%s`, scriptId), script, nil)
186 if err != nil {
187 return nil, err
188 }
189
190 spellVMCache[scriptId] = vmw
191 return vmw, nil
192}

Callers 1

TrySpellScriptEventFunction · 0.85

Calls 6

GetSpellFunction · 0.92
deleteFunction · 0.85
loadVMFunction · 0.85
StatMethod · 0.45
GetScriptPathMethod · 0.45
GetScriptMethod · 0.45

Tested by

no test coverage detected