Skip to content

Commit

Permalink
revise flatbuffers preload setup
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Mar 14, 2024
1 parent 27732ab commit edcfd60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
1 change: 0 additions & 1 deletion flow/connectors/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func (c *KafkaConnector) SyncRecords(ctx context.Context, req *model.SyncRecords
if err != nil {
return nil, fmt.Errorf("error executing script %s: %w", req.Script, err)
}
// discard results, for now rely on globals instead of script returning anything

var ok bool
lfn := ls.Env.RawGetString("onRecord")
Expand Down
47 changes: 19 additions & 28 deletions flow/pua/flatbuffers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,34 @@ import (
"github.com/yuin/gopher-lua"
)

/*
local m = {}
m.Builder = require("flatbuffers.builder").New
m.N = require("flatbuffers.numTypes")
m.view = require("flatbuffers.view")
m.binaryArray = require("flatbuffers.binaryarray")
return m
*/

func requireHelper(ls *lua.LState, m *lua.LTable, require lua.LValue, name string, path string) {
ls.Push(require)
ls.Push(lua.LString(path))
ls.Call(1, 1)
ls.SetField(m, name, ls.Get(-1))
ls.Pop(1)
}

func FlatBuffers_Loader(ls *lua.LState) int {
ls.PreloadModule("flatbuffers.binaryarray", FlatBuffers_BinaryArray_Loader)
ls.PreloadModule("flatbuffers.builder", FlatBuffers_Builder_Loader)
ls.PreloadModule("flatbuffers.numTypes", FlatBuffers_N_Loader)
ls.PreloadModule("flatbuffers.view", FlatBuffers_View_Loader)

m := ls.NewTable()
require := ls.GetGlobal("require")
ls.Push(require)
ls.Push(lua.LString("flatbuffers.builder"))
ls.Call(1, 1)
builder := ls.GetTable(ls.Get(-1), lua.LString("New"))
ls.SetField(m, "builder", builder)

ls.Push(ls.NewFunction(FlatBuffers_N_Loader))
ls.Call(0, 1)
m.RawSetString("N", ls.Get(-1))
ls.Pop(1)

requireHelper(ls, m, require, "N", "flatbuffers.numTypes")
requireHelper(ls, m, require, "view", "flatbuffers.view")
requireHelper(ls, m, require, "binaryArray", "flatbuffers.binaryarray")
ls.Push(ls.NewFunction(FlatBuffers_View_Loader))
ls.Call(0, 1)
m.RawSetString("view", ls.Get(-1))
ls.Pop(1)

ls.Push(ls.NewFunction(FlatBuffers_BinaryArray_Loader))
ls.Call(0, 1)
m.RawSetString("binaryArray", ls.Get(-1))
ls.Pop(1)

ls.Push(ls.NewFunction(FlatBuffers_Builder_Loader))
ls.Call(0, 1)
builder := ls.GetField(ls.Get(-1), "New")
m.RawSetString("builder", builder)
ls.Pop(1)

ls.Push(m)
return 1
Expand Down

0 comments on commit edcfd60

Please sign in to comment.