From 3015f3ea20573a0eada7372b45c255415736896f Mon Sep 17 00:00:00 2001 From: Mark Puha Date: Sat, 8 Feb 2025 14:35:20 +0100 Subject: [PATCH] change function initials --- adapter/lua.go | 15 ++++----------- adapter/lua_test.go | 6 +++--- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/adapter/lua.go b/adapter/lua.go index a6aceb1..47ce7b2 100644 --- a/adapter/lua.go +++ b/adapter/lua.go @@ -13,11 +13,11 @@ type Lua struct { } type LuaParams struct { - LuaCode64 string + Base64LuaCode string } func NewLua(params LuaParams) (*Lua, error) { - luaCode, err := base64.StdEncoding.DecodeString(params.LuaCode64) + luaCode, err := base64.StdEncoding.DecodeString(params.Base64LuaCode) if err != nil { return nil, err } @@ -26,7 +26,6 @@ func NewLua(params LuaParams) (*Lua, error) { state := lua.NewState() state.OpenLibs() - // Load and execute the Lua code if err := state.DoString(string(luaCode)); err != nil { return nil, fmt.Errorf("Error loading Lua code: %v\n", err) } @@ -38,10 +37,8 @@ func (l *Lua) Close() { } func (l *Lua) Generate(data []byte, counter int64) ([]byte, error) { - // Push the function onto the stack - l.state.GetGlobal("D_gen") + l.state.GetGlobal("d_gen") - // Push the argument l.state.PushBytes(data) l.state.PushInteger(counter) @@ -52,15 +49,12 @@ func (l *Lua) Generate(data []byte, counter int64) ([]byte, error) { result := l.state.ToBytes(-1) l.state.Pop(1) - fmt.Printf("Result: %s\n", string(result)) return result, nil } func (l *Lua) Parse(data []byte) ([]byte, error) { - // Push the function onto the stack - l.state.GetGlobal("D_parse") + l.state.GetGlobal("d_parse") - // Push the argument l.state.PushBytes(data) if err := l.state.Call(1, 1); err != nil { return nil, fmt.Errorf("Error calling Lua function: %v\n", err) @@ -69,6 +63,5 @@ func (l *Lua) Parse(data []byte) ([]byte, error) { result := l.state.ToBytes(-1) l.state.Pop(1) - fmt.Printf("Result: %s\n", string(result)) return result, nil } diff --git a/adapter/lua_test.go b/adapter/lua_test.go index 1d35651..08d5420 100644 --- a/adapter/lua_test.go +++ b/adapter/lua_test.go @@ -7,17 +7,17 @@ import ( func newLua() *Lua { lua, _ := NewLua(LuaParams{ /* - function D_gen(data, counter) + function d_gen(data, counter) local header = "header" return counter .. header .. data end - function D_parse(data) + function d_parse(data) local header = "10header" return string.sub(data, #header+1) end */ - LuaCode64: "ZnVuY3Rpb24gRF9nZW4oZGF0YSwgY291bnRlcikKCWxvY2FsIGhlYWRlciA9ICJoZWFkZXIiCglyZXR1cm4gY291bnRlciAuLiBoZWFkZXIgLi4gZGF0YQplbmQKCmZ1bmN0aW9uIERfcGFyc2UoZGF0YSkKCWxvY2FsIGhlYWRlciA9ICIxMGhlYWRlciIKCXJldHVybiBzdHJpbmcuc3ViKGRhdGEsICNoZWFkZXIrMSkKZW5kCg==", + Base64LuaCode: "ZnVuY3Rpb24gZF9nZW4oZGF0YSwgY291bnRlcikKCWxvY2FsIGhlYWRlciA9ICJoZWFkZXIiCglyZXR1cm4gY291bnRlciAuLiBoZWFkZXIgLi4gZGF0YQplbmQKCmZ1bmN0aW9uIGRfcGFyc2UoZGF0YSkKCWxvY2FsIGhlYWRlciA9ICIxMGhlYWRlciIKCXJldHVybiBzdHJpbmcuc3ViKGRhdGEsICNoZWFkZXIrMSkKZW5kCg==", }) return lua }