All Projects → jinq0123 → lua-flatbuffers

jinq0123 / lua-flatbuffers

Licence: Apache-2.0 License
FlatBuffers library for Lua.

Programming Languages

C++
36643 projects - #6 most used programming language
lua
6591 projects
Makefile
30231 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to lua-flatbuffers

zlmdb
Object-relational in-memory database layer based on LMDB
Stars: ✭ 22 (+57.14%)
Mutual labels:  flatbuffers
rust-flutter-reactive
This is a sample app to improve consistency over Mobile App Development.
Stars: ✭ 25 (+78.57%)
Mutual labels:  flatbuffers
roq-samples
How to use the Roq C++20 API for Live Cryptocurrency Algorithmic and High-Frequency Trading as well as for Back-Testing and Historical Simulation
Stars: ✭ 119 (+750%)
Mutual labels:  flatbuffers
react-native-fast-openpgp
OpenPGP for react native made with golang for fast performance
Stars: ✭ 29 (+107.14%)
Mutual labels:  flatbuffers
faabric
Messaging and state layer for distributed serverless applications
Stars: ✭ 39 (+178.57%)
Mutual labels:  flatbuffers
butte
No description or website provided.
Stars: ✭ 69 (+392.86%)
Mutual labels:  flatbuffers
luban
你的最佳游戏配置解决方案 {excel, csv, xls, xlsx, json, bson, xml, yaml, lua, unity scriptableobject} => {json, bson, xml, lua, yaml, protobuf(pb), msgpack, flatbuffers, erlang, custom template} data + {c++, java, c#, go(golang), lua, javascript(js), typescript(ts), erlang, rust, gdscript, protobuf schema, flatbuffers schema, custom template} code。
Stars: ✭ 1,660 (+11757.14%)
Mutual labels:  flatbuffers
gradle-flatbuffers-plugin
Gradle plugin for generating code from Google FlatBuffers schemas
Stars: ✭ 20 (+42.86%)
Mutual labels:  flatbuffers
FlexBuffersSwift
Swift implementation of FlexBuffers - a sub project of FlatBuffers
Stars: ✭ 24 (+71.43%)
Mutual labels:  flatbuffers
raster
A micro server framework, support coroutine, and parallel-computing, used for building flatbuffers/thrift/protobuf/http protocol service.
Stars: ✭ 19 (+35.71%)
Mutual labels:  flatbuffers
haskell-flatbuffers
An implementation of the flatbuffers protocol in Haskell.
Stars: ✭ 32 (+128.57%)
Mutual labels:  flatbuffers
Flatbuffers
FlatBuffers: Memory Efficient Serialization Library
Stars: ✭ 17,180 (+122614.29%)
Mutual labels:  flatbuffers
CppSerialization
Performance comparison of the most popular C++ serialization protocols such as Cap'n'Proto, FastBinaryEncoding, Flatbuffers, Protobuf, JSON
Stars: ✭ 89 (+535.71%)
Mutual labels:  flatbuffers

lua-flatbuffers

FlatBuffers library for Lua.

Build

Need submodule:

 $ git submodule update --init

Use premake5 to generate VS solution and linux Makefile, see here.

Vs2015 sln and Makefile are provided.

By default, it expects the Lua library to build under C++. If you really want to use Lua library compiled under C, you can define LUAINTF_LINK_LUA_COMPILED_IN_CXX to 0 in build/premake5.lua.
See: https://github.com/SteveKChiu/lua-intf

defines { "LUAINTF_LINK_LUA_COMPILED_IN_CXX=0" }

Lua library

  • For Linux, copy liblua.a to third_party/lib/.
  • For Windows, copy lua.lib debug and release to third_party/lib/Debug and Release dir.

FlatBuffers library

  • For Linux, build and install flatbuffers. Or copy lib to third_party/lib/.
  • For Windows, copy flatbuffers.lib debug and release to third_party/lib/Debug and Release dir.

Usage Example

flatc --binary --schema monster.fbs
local lfb = require("lfb")

-- Load a FlatBuffers schema file.
assert(lfb.load_bfbs_file("monster.bfbs"))

local monster = {
  pos = {
    x = 1,
    y = 2,
    z = 3,
  },
  hp = 300,
  name = "Orc",
}

-- Build a buffer.
local buf = assert(lfb.encode("Monster", monster))

-- Decode a flatbuffers string back to a Lua table.
local monster2 = assert(lfb.decode("Monster", buf))

Test

E:\Git\Lua\lua-flatbuffers_jinq0123\test>lua53pp.exe test.lua
All test passed.

E:\Git\Lua\lua-flatbuffers_jinq0123\test>
E:\Git\Lua\lua-flatbuffers_jinq0123\test>lua53pp.exe
Lua 5.3.2  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> package.cpath = package.cpath .. ";../bin/Debug/?.dll"
> lfb = require("lfb")
> lfb.load_bfbs_file("../third_party/flatbuffers/tests/monster_test.bfbs")
true
> buf = assert(lfb.encode("Monster", {name="N", hp=1234}))
> t = assert(lfb.decode("Monster", buf))
> inspect = require("inspect")
> inspect(t)
{
  color = 8,
  hp = 1234,
  mana = 150,
  name = "N",
  test_type = 0,
  testbool = false,
  testf = 3.1415901184082,
  testf2 = 3.0,
  testf3 = 0.0,
  testhashs32_fnv1 = 0,
  testhashs32_fnv1a = 0,
  testhashs64_fnv1 = 0,
  testhashs64_fnv1a = 0,
  testhashu32_fnv1 = 0,
  testhashu32_fnv1a = 0,
  testhashu64_fnv1 = 0,
  testhashu64_fnv1a = 0
}
>

Type Convertion

Number will be converted to string if necessary.

	buf = assert(lfb.encode("Monster", {name=123}))
	t = assert(lfb.decode("Monster", buf))
	assert("123" == t.name)

Integer will be converted from one type to another. Such as from int 256 to byte 0:

	buf = assert(lfb.encode("Test", {a=1, b=256}))  -- Test.b is byte
	t = assert(lfb.decode("Test", buf))
	assert(1 == t.a and 0 == t.b)

String can be converted to integer or float:

	buf = assert(lfb.encode("Test", {a=1, b="25"}))
	t = assert(lfb.decode("Test", buf))
	assert(1 == t.a and 25 == t.b)
	buf = assert(lfb.encode("Monster", {name="", testf="1.2"}))
	t = assert(lfb.decode("Monster", buf))
	assert(math.type(t.testf) == "float")
	assert(tostring(t.testf) == "1.2000000476837")

Can not convert float to integer.

	buf, err = lfb.encode("Test", {a=1.2, b=2})
	assert(err == "can not convert field Test.a(1.2) to integer")

Enum is integer, but input string enum will be converted to integer.

	local name = "TestSimpleTableWithEnum"
	buf = assert(lfb.encode(name, {color = 123}))
	t = assert(lfb.decode(name, buf))
	assert(123 == t.color)

	buf = assert(lfb.encode(name, {color = "Blue"}))
	t = assert(lfb.decode(name, buf))
	assert(8 == t.color)

Array only read from index 1 to len, ignoring others.

	buf = assert(lfb.encode("Monster", {name="", inventory={
		1,2, [-1]=-1, [100]=100, x=101}}))
	t = assert(lfb.decode("Monster", buf))
	assert(2 == #t.inventory)
	assert(nil == t.inventory[-1])
	assert(nil == t.inventory[100])

Todo

  • Support namespace. Reflection schema does not support namespaces #3899.
  • Sort key.
  • Verify key order.
  • Add file_identifier if root_type.
  • Load fbs file directly.

DavidFeng/lua-flatbuffers

https://github.com/DavidFeng/lua-flatbuffers

Another FlatBuffers library for lua 5.3, which implemented the reading of FlatBuffers but writing is to be implemented.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].