diff --git a/demo/src/app/views/root.zig b/demo/src/app/views/root.zig index e0ade83..1353b9e 100644 --- a/demo/src/app/views/root.zig +++ b/demo/src/app/views/root.zig @@ -3,8 +3,13 @@ const jetzig = @import("jetzig"); pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { var root = try data.object(); try root.put("message", data.string("Welcome to Jetzig!")); + try root.put("number", data.integer(customFunction(100, 200, 300))); try request.response.headers.append("x-example-header", "example header value"); return request.render(.ok); } + +fn customFunction(a: i32, b: i32, c: i32) i32 { + return a + b + c; +} diff --git a/src/GenerateRoutes.zig b/src/GenerateRoutes.zig index 3ebbf6e..119f116 100644 --- a/src/GenerateRoutes.zig +++ b/src/GenerateRoutes.zig @@ -430,6 +430,11 @@ fn parseFunction( var args = std.ArrayList(Arg).init(self.allocator); defer args.deinit(); + if (!isActionFunctionName(function_name)) { + self.allocator.free(function_name); + return null; + } + while (it.next()) |arg| { if (arg.name_token) |arg_token| { const arg_name = self.ast.tokenSlice(arg_token); @@ -478,3 +483,11 @@ fn parseTypeExpr(self: *Self, node: std.zig.Ast.Node) ![]const u8 { fn asNodeIndex(index: usize) std.zig.Ast.Node.Index { return @as(std.zig.Ast.Node.Index, @intCast(index)); } + +fn isActionFunctionName(name: []const u8) bool { + inline for (@typeInfo(jetzig.views.Route.Action).Enum.fields) |field| { + if (std.mem.eql(u8, field.name, name)) return true; + } + + return false; +}