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

Defined in:

types/libc.cr

Constructors

Instance Method Summary

Instance methods inherited from class Crygen::Abstract::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

Returns: an object class itself.


[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

Returns: an object class itself.


[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

Returns: an object class itself.


[View source]
def generate : String #

Generates a C lib. Returns: String


[View source]