Commit 1c61023c authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Handle arbitrary type conversions in Lua runtime input.

parent 8d9b2e0e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Add missing group chat channel message when a user is added to the group.
- Add missing group chat channel message when a user is kicked from the group.
- Add missing group chat channel message when a user is promoted in the group.
- Handle TIMESTAMPTZ return types in Lua runtime custom SQL queries.

## [2.6.0] - 2019-07-01
### Added
+8 −2
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@ package server

import (
	"fmt"

	"github.com/yuin/gopher-lua"
	"time"
)

const (
@@ -113,6 +113,7 @@ func RuntimeLuaConvertValue(l *lua.LState, val interface{}) lua.LValue {
	// Types looked up from:
	// https://golang.org/pkg/encoding/json/#Unmarshal
	// https://developers.google.com/protocol-buffers/docs/proto3#scalar
	// More types added based on observations.
	switch v := val.(type) {
	case bool:
		return lua.LBool(v)
@@ -156,8 +157,13 @@ func RuntimeLuaConvertValue(l *lua.LState, val interface{}) lua.LValue {
			lt.RawSetInt(k+1, RuntimeLuaConvertValue(l, v))
		}
		return lt
	case time.Time:
		return lua.LNumber(v.UTC().Unix())
	case nil:
		return lua.LNil
	default:
		return nil
		// Never return an actual Go `nil` or it will cause nil pointer dereferences inside gopher-lua.
		return lua.LNil
	}
}