Commit 498f9541 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Enable run once behaviour feature.

parent 0235f973
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -23,12 +23,15 @@ import (
type ExecutionMode int

const (
	RPC ExecutionMode = iota
	RunOnce ExecutionMode = iota
	RPC
	Match
)

func (e ExecutionMode) String() string {
	switch e {
	case RunOnce:
		return "run_once"
	case RPC:
		return "rpc"
	case Match:
+16 −2
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ func (n *NakamaModule) Loader(l *lua.LState) int {
		"notification_send":           n.notificationSend,
		"notifications_send":          n.notificationsSend,
		"wallet_write":                n.walletWrite,
		// "run_once": n.runOnce,
		"run_once":                    n.runOnce,
	}
	mod := l.SetFuncs(l.CreateTable(len(functions), len(functions)), functions)

@@ -1828,9 +1828,23 @@ func (n *NakamaModule) runOnce(l *lua.LState) int {
			return
		}

		ctx := NewLuaContext(l, ConvertMap(l, n.config.GetRuntime().Environment), RunOnce, "", "", 0, "")

		l.Push(LSentinel)
		l.Push(fn)
		if err := l.PCall(0, lua.MultRet, nil); err != nil {
		l.Push(ctx)
		if err := l.PCall(1, lua.MultRet, nil); err != nil {
			l.RaiseError("error in run_once function: %v", err.Error())
			return
		}

		// Unwind the stack up to and including our sentinel value, effectively discarding any returned parameters.
		for {
			v := l.Get(-1)
			l.Pop(1)
			if v.Type() == LTSentinel {
				break
			}
		}
	})