Skip to content
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

Add methods to add C functions, enums, structs and unions #2

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

tamdaz
Copy link
Owner

@tamdaz tamdaz commented Jan 27, 2025

Description

Generate C libs where it is possible to add functions, structs, enums and unions.

Code generation

libc_type = Crygen::Types::LibC.new("C")
libc_type.add_function("getch", "Int32")
libc_type.add_function("time", "Int32")
libc_type.add_function("getpid", "Int32")
libc_type.add_struct("TimeZone", [
  {"field_one", "Int32"},
  {"field_two", "Int32"},
])
libc_type.add_struct("DateTime", [
  {"timestamp", "Int64"},
])
libc_type.add_union("IntOrFloat", [
  {"some_int", "Int32"},
  {"some_float", "Float64"},
])
libc_type.add_union("CharOrString", [
  {"some_char", "Char"},
  {"some_string", "String"},
])

puts libc_type.generate

Code output

lib C
  struct TimeZone
    field_one : Int32
    field_two : Int32
  end

  struct DateTime
    timestamp : Int64
  end

  union IntOrFloat
    some_int : Int32
    some_float : Float64
  end

  union CharOrString
    some_char : Char
    some_string : String
  end

  fun getch : Int32
  fun time : Int32
  fun getpid : Int32
end

Verified

This commit was signed with the committer’s verified signature.
tamdaz Zohir Tamda

Verified

This commit was signed with the committer’s verified signature.
tamdaz Zohir Tamda
@tamdaz tamdaz added the enhancement New feature or request label Jan 27, 2025
@tamdaz tamdaz self-assigned this Jan 27, 2025

Verified

This commit was signed with the committer’s verified signature.
tamdaz Zohir Tamda
@tamdaz tamdaz merged commit 5e9d03b into main Jan 29, 2025
2 checks passed
@tamdaz tamdaz deleted the add/libc-type branch January 29, 2025 18:18
@tamdaz tamdaz added this to the v0.2.0 milestone Feb 3, 2025
Repository owner locked as resolved and limited conversation to collaborators Feb 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant