Skip to content

Running on ESP32: load() function not working #265

@yesItsGaren

Description

@yesItsGaren

Hello, I am new with Lua. I am trying to use it on the ESP32.
I have already tried using it to run the example script on Windows and it works flawlessly.
The problems start when I try to use the pb.c and import it using require "pb".

Some prerequisite info:

  • protoc.lua is pushed as a string using:

    lua_getglobal(L, "package");
    lua_getfield(L, -1, "preload");
    error = luaL_loadstring(L, protoc_Lua);
    lua_setfield(L, -2, "protoc");

  • The protoc.new() function seems to work, since I tried to print something in the Parse.new()

  • The protoc:load(string) does not work and is causing the following error:
    Lua Error Run[2]: [string "..."]:8: attempt to call a nil value (method 'load')

  • Tried using Parser:compile(), but I am getting the following error:
    Lua Error Run[2]: [string "..."]:8: attempt to call a nil value (method 'compile')

  • Tried using the pb.load(user_data, type) instead but I get the following error:
    Lua Error Run[2]: [string "..."]:38: bad argument fixed disambiguity #1 to 'encode' (type 'Person' does not exist)
    Note that I declared the function mapping table as global, this enabled me to use the functions without using "require". But still i guess the pb.load() function does not seem to work properly.

  • I am running this example script by pushing it as a string :

const char test_script_protobuf[] = R"delimiter(
local protoc = require "protoc"
local pb = require "pb"

local p = protoc.new()

-- load schema from text (just for demo, use protoc.new() in real world)
local retVal = p:load ([[
message Phone {
optional string name = 1;
optional int64 phonenumber = 2;
}
message Person {
optional string name = 1;
optional int32 age = 2;
optional string address = 3;
repeated Phone contacts = 4;
} ]],"Person")

print("p:load ")
print(retVal)

-- lua table data
local data = {
name = "ilse",
age = 18,
contacts = {
{ name = "alice", phonenumber = 12312341234 },
{ name = "bob", phonenumber = 45645674567 }
}
}

-- encode lua table data into binary format in lua string and return
local bytes = assert(pb.encode("Person", data))
print(pb.tohex(bytes))

-- and decode the binary data back into lua table
local data2 = assert(pb.decode("Person", bytes))
print(require "serpent".block(data2))

)delimiter";

My question: What am I missing here? How can I make the load() function and other functions to run properly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions