luaaaaah/src/types.zig

42 lines
733 B
Zig
Raw Normal View History

const std = @import("std");
2023-09-15 11:07:50 +02:00
pub const Numeral = union(enum)
{
Integer: i64,
Float: f64,
};
pub const Table = struct
{
2023-11-17 01:37:29 +01:00
items: std.HashMap(Value, Value, std.hash_map.AutoContext(Value), std.hash_map.default_max_load_percentage),
pub fn insert(self: *const Table, key: Value, value: Value) !bool
{
self.items.put(key, value);
}
pub fn get(self: *const Table, key: Value) !Value
{
const value = self.items.get(key);
return if(value == null) Value.Nil else value.?;
}
};
pub const Value = union(enum)
{
Nil,
Bool: bool,
Numeral: Numeral,
2023-11-17 01:37:29 +01:00
String: []const u8,
Table: *Table,
};
pub const CodeRegion = struct
{
start: ?CodeLocation,
length: usize,
};
pub const CodeLocation = struct
{
line: usize,
col: usize,
};