summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authoraardappel <aardappel@gmail.com>2019-05-22 11:48:10 -0700
committeraardappel <aardappel@gmail.com>2019-05-22 11:48:10 -0700
commit30ac512a540249e1e716000b970283ac24807073 (patch)
tree95cea2110e8d4474fee9ffd7b8261c38aded47c5 /samples
parentb04736f9bd88af2a10f48a2ca3bd25a0e42d5150 (diff)
downloadflatbuffers-30ac512a540249e1e716000b970283ac24807073.tar.gz
flatbuffers-30ac512a540249e1e716000b970283ac24807073.tar.bz2
flatbuffers-30ac512a540249e1e716000b970283ac24807073.zip
Fixed Lobster implementation to work with latest language features
Diffstat (limited to 'samples')
-rw-r--r--samples/monster_generated.lobster75
-rw-r--r--samples/sample_binary.lobster6
-rw-r--r--samples/sample_text.lobster12
3 files changed, 46 insertions, 47 deletions
diff --git a/samples/monster_generated.lobster b/samples/monster_generated.lobster
index 409e77d7..7bf3f4cc 100644
--- a/samples/monster_generated.lobster
+++ b/samples/monster_generated.lobster
@@ -1,31 +1,30 @@
// automatically generated by the FlatBuffers compiler, do not modify
-
-include "flatbuffers.lobster"
+import flatbuffers
namespace MyGame_Sample
-enum +
- Color_Red = 0,
- Color_Green = 1,
+enum Color:
+ Color_Red = 0
+ Color_Green = 1
Color_Blue = 2
-enum +
- Equipment_NONE = 0,
+enum Equipment:
+ Equipment_NONE = 0
Equipment_Weapon = 1
-struct Vec3
+class Vec3
-struct Monster
+class Monster
-struct Weapon
+class Weapon
-struct Vec3 : flatbuffers_handle
+class Vec3 : flatbuffers_handle
def x():
- buf_.read_float32_le(pos_ + 0)
+ return buf_.read_float32_le(pos_ + 0)
def y():
- buf_.read_float32_le(pos_ + 4)
+ return buf_.read_float32_le(pos_ + 4)
def z():
- buf_.read_float32_le(pos_ + 8)
+ return buf_.read_float32_le(pos_ + 8)
def CreateVec3(b_:flatbuffers_builder, x:float, y:float, z:float):
b_.Prep(4, 12)
@@ -34,36 +33,36 @@ def CreateVec3(b_:flatbuffers_builder, x:float, y:float, z:float):
b_.PrependFloat32(x)
return b_.Offset()
-struct Monster : flatbuffers_handle
+class Monster : flatbuffers_handle
def pos():
- o := buf_.flatbuffers_field_struct(pos_, 4)
- if o: MyGame_Sample_Vec3 { buf_, o } else: nil
+ let o = buf_.flatbuffers_field_struct(pos_, 4)
+ return if o: MyGame_Sample_Vec3 { buf_, o } else: nil
def mana():
- buf_.flatbuffers_field_int16(pos_, 6, 150)
+ return buf_.flatbuffers_field_int16(pos_, 6, 150)
def hp():
- buf_.flatbuffers_field_int16(pos_, 8, 100)
+ return buf_.flatbuffers_field_int16(pos_, 8, 100)
def name():
- buf_.flatbuffers_field_string(pos_, 10)
+ return buf_.flatbuffers_field_string(pos_, 10)
def inventory(i:int):
- buf_.read_int8_le(buf_.flatbuffers_field_vector(pos_, 14) + i * 1)
+ return buf_.read_int8_le(buf_.flatbuffers_field_vector(pos_, 14) + i * 1)
def inventory_length():
- buf_.flatbuffers_field_vector_len(pos_, 14)
+ return buf_.flatbuffers_field_vector_len(pos_, 14)
def color():
- buf_.flatbuffers_field_int8(pos_, 16, 2)
+ return buf_.flatbuffers_field_int8(pos_, 16, 2)
def weapons(i:int):
- MyGame_Sample_Weapon { buf_, buf_.flatbuffers_indirect(buf_.flatbuffers_field_vector(pos_, 18) + i * 4) }
+ return MyGame_Sample_Weapon { buf_, buf_.flatbuffers_indirect(buf_.flatbuffers_field_vector(pos_, 18) + i * 4) }
def weapons_length():
- buf_.flatbuffers_field_vector_len(pos_, 18)
+ return buf_.flatbuffers_field_vector_len(pos_, 18)
def equipped_type():
- buf_.flatbuffers_field_int8(pos_, 20, 0)
+ return buf_.flatbuffers_field_int8(pos_, 20, 0)
def equipped_as_Weapon():
- MyGame_Sample_Weapon { buf_, buf_.flatbuffers_field_table(pos_, 22) }
+ return MyGame_Sample_Weapon { buf_, buf_.flatbuffers_field_table(pos_, 22) }
def path(i:int):
- MyGame_Sample_Vec3 { buf_, buf_.flatbuffers_field_vector(pos_, 24) + i * 12 }
+ return MyGame_Sample_Vec3 { buf_, buf_.flatbuffers_field_vector(pos_, 24) + i * 12 }
def path_length():
- buf_.flatbuffers_field_vector_len(pos_, 24)
+ return buf_.flatbuffers_field_vector_len(pos_, 24)
-def GetRootAsMonster(buf:string): Monster { buf, buf.flatbuffers_indirect(0) }
+def GetRootAsMonster(buf:string): return Monster { buf, buf.flatbuffers_indirect(0) }
def MonsterStart(b_:flatbuffers_builder):
b_.StartObject(11)
@@ -82,7 +81,7 @@ def MonsterStartInventoryVector(b_:flatbuffers_builder, n_:int):
def MonsterCreateInventoryVector(b_:flatbuffers_builder, v_:[int]):
b_.StartVector(1, v_.length, 1)
reverse(v_) e_: b_.PrependUint8(e_)
- b_.EndVector(v_.length)
+ return b_.EndVector(v_.length)
def MonsterAddColor(b_:flatbuffers_builder, color:int):
b_.PrependInt8Slot(6, color, 2)
def MonsterAddWeapons(b_:flatbuffers_builder, weapons:int):
@@ -92,7 +91,7 @@ def MonsterStartWeaponsVector(b_:flatbuffers_builder, n_:int):
def MonsterCreateWeaponsVector(b_:flatbuffers_builder, v_:[int]):
b_.StartVector(4, v_.length, 4)
reverse(v_) e_: b_.PrependUOffsetTRelative(e_)
- b_.EndVector(v_.length)
+ return b_.EndVector(v_.length)
def MonsterAddEquippedType(b_:flatbuffers_builder, equipped_type:int):
b_.PrependUint8Slot(8, equipped_type, 0)
def MonsterAddEquipped(b_:flatbuffers_builder, equipped:int):
@@ -102,15 +101,15 @@ def MonsterAddPath(b_:flatbuffers_builder, path:int):
def MonsterStartPathVector(b_:flatbuffers_builder, n_:int):
b_.StartVector(12, n_, 4)
def MonsterEnd(b_:flatbuffers_builder):
- b_.EndObject()
+ return b_.EndObject()
-struct Weapon : flatbuffers_handle
+class Weapon : flatbuffers_handle
def name():
- buf_.flatbuffers_field_string(pos_, 4)
+ return buf_.flatbuffers_field_string(pos_, 4)
def damage():
- buf_.flatbuffers_field_int16(pos_, 6, 0)
+ return buf_.flatbuffers_field_int16(pos_, 6, 0)
-def GetRootAsWeapon(buf:string): Weapon { buf, buf.flatbuffers_indirect(0) }
+def GetRootAsWeapon(buf:string): return Weapon { buf, buf.flatbuffers_indirect(0) }
def WeaponStart(b_:flatbuffers_builder):
b_.StartObject(2)
@@ -119,5 +118,5 @@ def WeaponAddName(b_:flatbuffers_builder, name:int):
def WeaponAddDamage(b_:flatbuffers_builder, damage:int):
b_.PrependInt16Slot(1, damage, 0)
def WeaponEnd(b_:flatbuffers_builder):
- b_.EndObject()
+ return b_.EndObject()
diff --git a/samples/sample_binary.lobster b/samples/sample_binary.lobster
index 0434af06..ae3dbe1d 100644
--- a/samples/sample_binary.lobster
+++ b/samples/sample_binary.lobster
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-include from "../lobster/"
-include "monster_generated.lobster"
+import from "../lobster/"
+import monster_generated
// Example of how to use FlatBuffers to create and read binary buffers.
@@ -24,7 +24,7 @@ let b = flatbuffers_builder {}
let weapon_names = [ "Sword", "Axe" ]
let weapon_damages = [ 3, 5 ]
-weapon_offsets := map(weapon_names) name, i:
+let weapon_offsets = map(weapon_names) name, i:
let ns = b.CreateString(name)
b.MyGame_Sample_WeaponStart()
b.MyGame_Sample_WeaponAddName(ns)
diff --git a/samples/sample_text.lobster b/samples/sample_text.lobster
index 9da4fa25..26b3eaff 100644
--- a/samples/sample_text.lobster
+++ b/samples/sample_text.lobster
@@ -12,20 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-include from "../lobster/"
-include "monster_generated.lobster"
+import from "../lobster/"
+import monster_generated
// Example how to interop with JSON.
// Test loading some JSON, converting it to a binary FlatBuffer and back again.
// First read the schema and JSON data.
-schema := read_file("monster.fbs", true)
-json := read_file("monsterdata.json", true)
+let schema = read_file("monster.fbs", true)
+let json = read_file("monsterdata.json", true)
assert schema and json
// Parse JSON to binary:
-fb, err1 := flatbuffers_json_to_binary(schema, json, [])
+let fb, err1 = flatbuffers_json_to_binary(schema, json, [])
assert not err1
// Access one field in it, just to check:
@@ -33,7 +33,7 @@ let monster = MyGame_Sample_GetRootAsMonster(fb)
assert monster.name == "Orc"
// Convert binary back to JSON:
-json2, err2 := flatbuffers_binary_to_json(schema, fb, [])
+let json2, err2 = flatbuffers_binary_to_json(schema, fb, [])
assert not err2
// The generated JSON should be exactly equal to the original!