モデルの説明をLuaに保存し、ノンシーケンシャルで読みたい。すべてのデータは増分順に保存されます
device_pins =
{
{is_digital=true, name = "A", number = 1, on_time=15000000000, off_time=22000000000},
{is_digital=true, name = "B", number = 2, on_time=15000000000, off_time=22000000000},
{is_digital=true, name = "C", number = 3, on_time=15000000000, off_time=22000000000}
}
そのデータを C 構造体に格納する方法とほとんど同じです。したがって、device_pins[1..3] のように device_pins をループし、Lua で行うようにサブテーブル値にアクセスしたい: device_pins[1].name など。これまでのところ、テーブルを反復処理できますが、サブテーブル フィールドにアクセスできません。 、 lua_getfield を試しましたが、ここでは適していないようです
lua_getglobal (luactx, "device_pins");
if (0 == lua_istable(luactx, 1))
{
out_log("No table found");
}
lua_pushnil(luactx);
while (lua_next(luactx, 1) != 0)
{
out_log(lua_typename(luactx, lua_type(luactx, -1)));
lua_pop(luactx, 1);
}