diff options
| author | unwox <me@unwox.com> | 2024-06-13 13:09:24 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2024-06-13 13:09:24 +0600 |
| commit | ecec880f946c3ff4cbad79223f6941e16e8f19c0 (patch) | |
| tree | 8ce9b7f562de379f9e5c0135e515cbf47cfc1e33 /lua.go | |
| parent | d00ee9196d08cf824c9ec55f2987399c751df966 (diff) | |
add RestoreStackFunc method for preventing stack leaks
Diffstat (limited to 'lua.go')
| -rw-r--r-- | lua.go | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -122,3 +122,21 @@ func (l *Lua) PushTableItem (key string) { C.lua_pushstring(l.l, ckey); C.lua_gettable(l.l, -2); } + +func (l *Lua) RestoreStackFunc() func () { + before := l.StackLen() + return func () { + after := l.StackLen() + diff := after - before + if diff == 0 { + return + } else if diff < 0 { + log.Fatalf( + "too many stack pops: len before: %d, after: %d\n", + before, + after, + ) + } + C.lua_settop(l.l, C.int(before)) + } +} |
