class Crygen::Types::LibC

Overview

A class that generates a C library.

libc_type = Crygen::Types::LibC.new("C")
libc_type.add_function("getch", "Int32")
libc_type.generate

Output:

lib C
  fun getch : Int32
end

Included Modules

Defined in:

types/libc.cr

Constructors

Instance Method Summary

Instance methods inherited from module Crygen::Modules::Annotation

add_annotation(annotation_type : Crygen::Types::Annotation) : self add_annotation

Instance methods inherited from module Crygen::Helpers::Annotation

add_link(name : String) : self add_link, as_deprecated(message : String) : self
as_deprecated : self
as_deprecated
, as_experimental(message : String) : self
as_experimental : self
as_experimental
, as_flags : self as_flags

Instance methods inherited from class Crygen::Interfaces::GeneratorInterface

generate : String generate

Constructor Detail

def self.new(name : String) #

[View source]

Instance Method Detail

def add_function(name : String, return_type : String, args : Array(Tuple(String, String)) | Nil = nil) : self #

Adds a C function (name, return type, and optional arguments).

libc_type = Crygen::Types::LibC.new("C")
libc_type.add_function("getch", "Int32", [{"arg1", "Int32"}, {"arg2", "Int32"}])

Output:

lib C
  fun getch(arg1 : Int32, arg2 : Int32) : Int32
end

[View source]
def add_struct(name : String, fields : FieldArray) : self #

Adds a struct.

libc_type = Crygen::Types::LibC.new("C")
libc_type.add_struct("Person", [{"name", "String"}, {"age", "Int32"}])

Output:

lib C
  struct Person
    name : String
    age : Int32
  end
end

[View source]
def add_union(name : String, fields : FieldArray) : self #

Adds an union.

libc_type = Crygen::Types::LibC.new("C")
libc_type.add_union("Person", [{"name", "String"}, {"age", "Int32"}])

Output:

lib C
  union Person
    name : String
    age : Int32
  end
end

[View source]
def generate : String #

Generates a C lib.


[View source]