Skip to content

Luals docgen #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Sep 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3c3e355
proof of concept
VisenDev Sep 21, 2024
c3dd769
more types working
VisenDev Sep 21, 2024
1a04340
more types working
VisenDev Sep 21, 2024
65488f8
custom build step now working
VisenDev Sep 21, 2024
84ce7ae
integrated things better
VisenDev Sep 23, 2024
c654025
fixed segfaults, still need to add install step
VisenDev Sep 23, 2024
9133013
refactored in new file
VisenDev Sep 24, 2024
3d6b352
fixed memory corruption issues
VisenDev Sep 24, 2024
7455f58
polished implementation
VisenDev Sep 24, 2024
8b4da8b
removed old comments
VisenDev Sep 24, 2024
cd0184d
removed old testing code
VisenDev Sep 24, 2024
4704964
reworked define system to support build arguments
VisenDev Sep 25, 2024
7a3a31f
add allocator parameter
VisenDev Sep 25, 2024
6c348cb
properly close file
VisenDev Sep 25, 2024
1c27125
adding debug logging for testing
VisenDev Sep 25, 2024
a6de64c
added init capacity
VisenDev Sep 25, 2024
8d53895
added more debugging logs
VisenDev Sep 25, 2024
2a29d99
removed deinit from hashmap for testing
VisenDev Sep 25, 2024
a6d8645
allocator experiments
VisenDev Sep 25, 2024
a4d69f1
changing id test
VisenDev Sep 25, 2024
572dfac
more changes to how Ids are defined:
VisenDev Sep 25, 2024
44a7d58
reworked how arraylists are stored
VisenDev Sep 25, 2024
b4402a9
removed debugging print statements, fixed bug
VisenDev Sep 25, 2024
8f01465
minor testing change
VisenDev Sep 25, 2024
435668b
added more spacing between types
VisenDev Sep 25, 2024
b878e3f
added annotations for testing
VisenDev Sep 25, 2024
07a2388
totally reworked implementation to fix bugs
VisenDev Sep 25, 2024
547c0da
allow struct fields with default values to be null
VisenDev Sep 25, 2024
4f6f021
change how optional fields are notated
VisenDev Sep 25, 2024
6ed5166
revert back to old optional field syntax
VisenDev Sep 25, 2024
5275b0a
added unit test
VisenDev Sep 27, 2024
1c8afa7
remove outdated decls
VisenDev Sep 27, 2024
21353cb
remove error union return type from build.zig
VisenDev Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reworked how arraylists are stored
  • Loading branch information
VisenDev committed Sep 25, 2024
commit 44a7d5869ea84612c6f9920017e26047c771fd29
78 changes: 41 additions & 37 deletions src/define.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");

const String = std.ArrayList(u8);
const String = std.ArrayListUnmanaged(u8);
const Database = std.StringHashMap(String);

pub const DefineEntry = struct {
Expand All @@ -20,6 +20,7 @@ pub fn define(
std.debug.print("defining: {any}\n", .{def.type});
_ = try addClass(alloc, &database, def.type);
std.debug.print("finished defining: {any}\n", .{def.type});
std.debug.print("actual stored value: \n\n{s}\n\n", .{database.get(@typeName(def.type)).?.items});
}

std.debug.print("opening output file: {s}\n", .{absolute_output_path});
Expand All @@ -30,20 +31,20 @@ pub fn define(
try file.writeAll(file_header);

std.debug.print("writing to file\n", .{});
var iter = database.valueIterator();
var iter = database.iterator();
while (iter.next()) |val| {
std.debug.print(" - writing item\n", .{});
try file.writeAll(val.items);
std.debug.print(" - writing item: {s}\n", .{val.key_ptr.*});
try file.writeAll(val.value_ptr.items);
try file.writeAll("\n");
}
std.debug.print("finished writing to file\n", .{});

try file.setEndPos(try file.getPos());

std.debug.print("Freeing memory\n", .{});
iter = database.valueIterator();
iter = database.iterator();
while (iter.next()) |val| {
val.deinit();
val.value_ptr.deinit(alloc);
}
}

Expand All @@ -63,17 +64,18 @@ fn addEnum(
) ![]const u8 {
const name = (comptime std.fs.path.extension(@typeName(T)))[1..];
if (database.contains(@typeName(T)) == false) {
var text = try String.initCapacity(alloc, 16);
try database.put(@typeName(T), text);
const text_basis = try String.initCapacity(alloc, 16);
try database.putNoClobber(@typeName(T), text_basis);
const text = database.getPtr(@typeName(T)).?;

try text.appendSlice("---@alias ");
try text.appendSlice(name);
try text.appendSlice("\n");
try text.appendSlice(alloc, "---@alias ");
try text.appendSlice(alloc, name);
try text.appendSlice(alloc, "\n");

inline for (@typeInfo(T).Enum.fields) |field| {
try text.appendSlice("---|\' \"");
try text.appendSlice(field.name);
try text.appendSlice("\" \'\n");
try text.appendSlice(alloc, "---|\' \"");
try text.appendSlice(alloc, field.name);
try text.appendSlice(alloc, "\" \'\n");
}
}
return name;
Expand All @@ -82,30 +84,32 @@ fn addEnum(
fn addClass(alloc: std.mem.Allocator, database: *Database, comptime T: type) ![]const u8 {
const name = (comptime std.fs.path.extension(@typeName(T)))[1..];
if (database.contains(@typeName(T)) == false) {
var text = try String.initCapacity(alloc, 16);
try database.put(@typeName(T), text);
const text_basis = try String.initCapacity(alloc, 16);
try database.putNoClobber(@typeName(T), text_basis);
const text = database.getPtr(@typeName(T)).?;

std.debug.print("defining: {s}\n", .{name});
try addClassName(&text, name);
try addClassFields(alloc, database, &text, @typeInfo(T).Struct.fields);
try addClassName(alloc, text, name);
try addClassFields(alloc, database, text, @typeInfo(T).Struct.fields);
std.debug.print("finished defining: {s}\n", .{name});
std.debug.print("final value: \n{s}\n", .{text.items});
}
return name;
}

fn addClassName(text: *String, name: []const u8) !void {
try text.appendSlice("---@class ");
try text.appendSlice(name);
try text.appendSlice("\n");
fn addClassName(alloc: std.mem.Allocator, text: *String, name: []const u8) !void {
try text.appendSlice(alloc, "---@class ");
try text.appendSlice(alloc, name);
try text.appendSlice(alloc, "\n");
}

fn addClassField(alloc: std.mem.Allocator, database: *Database, text: *String, comptime field: std.builtin.Type.StructField) !void {
std.debug.print(" - adding field: {s}\n", .{field.name});
try text.appendSlice("---@field ");
try text.appendSlice(field.name);
try text.appendSlice(" ");
try text.appendSlice(alloc, "---@field ");
try text.appendSlice(alloc, field.name);
try text.appendSlice(alloc, " ");
try addType(alloc, database, text, field.type);
try text.appendSlice("\n");
try text.appendSlice(alloc, "\n");
}

fn addClassFields(
Expand All @@ -126,46 +130,46 @@ fn addType(alloc: std.mem.Allocator, database: *Database, text: *String, comptim
switch (@typeInfo(T)) {
.Struct => {
const name = try addClass(alloc, database, T);
try text.appendSlice(name);
try text.appendSlice(alloc, name);
},
.Pointer => |info| {
if (info.child == u8 and info.size == .Slice) {
try text.appendSlice("string");
try text.appendSlice(alloc, "string");
} else switch (info.size) {
.One => {
try text.appendSlice("lightuserdata");
try text.appendSlice(alloc, "lightuserdata");
},
.C, .Many, .Slice => {
try addType(alloc, database, text, info.child);
try text.appendSlice("[]");
try text.appendSlice(alloc, "[]");
},
}
},
.Array => |info| {
try addType(alloc, database, text, info.child);
try text.appendSlice("[]");
try text.appendSlice(alloc, "[]");
},

.Vector => |info| {
try addType(alloc, database, text, info.child);
try text.appendSlice("[]");
try text.appendSlice(alloc, "[]");
},
.Optional => |info| {
try addType(alloc, database, text, info.child);
try text.appendSlice("?");
try text.appendSlice(alloc, "?");
},
.Enum => {
const name = try addEnum(alloc, database, T);
try text.appendSlice(name);
try text.appendSlice(alloc, name);
},
.Int => {
try text.appendSlice("integer");
try text.appendSlice(alloc, "integer");
},
.Float => {
try text.appendSlice("number");
try text.appendSlice(alloc, "number");
},
.Bool => {
try text.appendSlice("boolean");
try text.appendSlice(alloc, "boolean");
},
else => {
@compileLog(T);
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy