Paste: c-struct offset illustration

Author: jedahu
Mode: c++
Date: Thu, 30 Apr 2009 22:40:47
Plain Text |
#ifndef SMOKE_WRAPPER_H
#define SMOKE_WRAPPER_H

#include <smoke.h>
#include <smoke/qt_smoke.h>

extern "C" {

  void init_qt_smoke();
  Smoke* qt_smoke();
  void delete_qt_smoke();

  Smoke::Type* smoke_types(Smoke* s);
  Smoke::Class* smoke_classes(Smoke* s);
  Smoke::Method* smoke_methods(Smoke* s);
  Smoke::Index* smoke_inheritanceList(Smoke* s);
  Smoke::Index* smoke_argumentList(Smoke* s);
  Smoke::Index* smoke_ambiguousMethodList(Smoke* s);
  Smoke::MethodMap* smoke_methodMaps(Smoke* s);
  const char** smoke_methodNames(Smoke* s);

  Smoke::Index smoke_numTypes(Smoke* s);
  Smoke::Index smoke_numClasses(Smoke* s);
  Smoke::Index smoke_numMethods(Smoke* s);
  Smoke::Index smoke_numMethodMaps(Smoke* s);
  Smoke::Index smoke_numMethodNames(Smoke* s);

  Smoke::ModuleIndex smoke_findClass(Smoke* s, const char* c);
  Smoke::ModuleIndex smoke_findMethod(Smoke* s, const char* c, const char* name);
}

#endif

Annotation: smoke_wrapper.cpp

Author: jedahu
Mode: c++
Date: Thu, 30 Apr 2009 22:41:37
Plain Text |
#include "c_wrapper.h"

extern "C" {

  void init_qt_smoke() {
    init_qt_Smoke();
  }

  Smoke* qt_smoke() {
    return qt_Smoke;
  }

  void delete_qt_smoke() {
    delete qt_Smoke;
  }

  Smoke::Type* smoke_types(Smoke* s) {
    return s->types;
  }
  Smoke::Class* smoke_classes(Smoke* s) {
    return s->classes;
  }
  Smoke::Method* smoke_methods(Smoke* s) {
    return s->methods;
  }
  Smoke::Index* smoke_inheritanceList(Smoke* s) {
    return s->inheritanceList;
  }
  Smoke::Index* smoke_argumentList(Smoke* s) {
    return s->argumentList;
  }
  Smoke::Index* smoke_ambiguousMethodList(Smoke* s) {
    return s->ambiguousMethodList;
  }
  Smoke::MethodMap* smoke_methodMaps(Smoke* s) {
    return s->methodMaps;
  }
  const char** smoke_methodNames(Smoke* s) {
    return s->methodNames;
  }

  Smoke::Index smoke_numTypes(Smoke* s) {
    return s->numTypes;
  }
  Smoke::Index smoke_numClasses(Smoke* s) {
    return s->numClasses;
  }
  Smoke::Index smoke_numMethods(Smoke* s) {
    return s->numMethods;
  }
  Smoke::Index smoke_numMethodMaps(Smoke* s) {
    return s->numMethodMaps;
  }
  Smoke::Index smoke_numMethodNames(Smoke* s) {
    return s->numMethodNames;
  }

  Smoke::ModuleIndex smoke_findClass(Smoke* s, const char* c) {
    return s->findClass(c);
  }

  Smoke::ModuleIndex smoke_findMethod(Smoke* s, const char* c, const char* name) {
    return s->findMethod(c, name);
  }
}

Annotation: s/c_wrapper/smoke_wrapper/

Author: jedahu
Mode: factor
Date: Thu, 30 Apr 2009 22:43:27
Plain Text |
! test.cpp should include smoke_wrapper.cpp, not c_wrapper.cpp

Annotation: smoke/ffi/ffi.factor

Author: jedahu
Mode: factor
Date: Thu, 30 Apr 2009 22:44:20
Plain Text |
USING: alien alien.destructors alien.syntax alien.libraries generalizations
   kernel sequences ;

IN: smoke.ffi

<< "lsmoke" "libsmokewrapper.so" "cdecl" add-library >>

LIBRARY: lsmoke

TYPEDEF: void Smoke
TYPEDEF: void StackItem
TYPEDEF: short Index

C-STRUCT: ModuleIndex
    { "Smoke*" "smoke" }
    { "Index" "index" } ;

C-STRUCT: Class
    { "char*" "className" } ! Name of the class
    { "bool" "external" }   ! Whether the class is in another module
    { "Index" "parents" }   ! Index into inheritanceList
    { "void*" "classFn" }   ! Calls any method in the class
    { "void*" "enumFn" }    ! Handles enum pointers
    { "ushort" "flags" } ;  ! ClassFlags

C-STRUCT: Method
    { "Index" "classId" }  ! Index into classes
    { "Index" "name" }     ! Index into methodNames; real name
    { "Index" "args" }     ! Index into argumentList
    { "uchar" "numArgs" }  ! Number of arguments
    { "uchar" "flags" }    ! MethodFlags (const/static/etc...)
    { "Index" "ret" }      ! Index into types for the return type
    { "Index" "method" } ; ! Passed to Class.classFn, to call method

C-STRUCT: Type
    { "char*" "name" }     ! Stringified type name
    { "Index" "classId" }  ! Index into classes. -1 for none
    { "ushort" "flags" } ; ! TypeFlags

C-STRUCT: MethodMap
    { "Index" "classId" }  ! Index into classes
    { "Index" "name" }     ! Index into methodNames; munged name
    { "Index" "method" } ; ! Index into methods

FUNCTION: void init_qt_smoke ( ) ;
FUNCTION: Smoke* qt_smoke ( ) ;
FUNCTION: void delete_qt_smoke ( ) ;

FUNCTION: Type* smoke_types ( Smoke* s ) ;
FUNCTION: Class* smoke_classes ( Smoke* s ) ;
FUNCTION: Method* smoke_methods ( Smoke* s ) ;
FUNCTION: Index* smoke_inheritanceList ( Smoke* s ) ;
FUNCTION: Index* smoke_argumentList ( Smoke* s ) ;
FUNCTION: Index* smoke_ambiguousMethodList ( Smoke* s ) ;
FUNCTION: MethodMap* smoke_methodMaps ( Smoke* s ) ;
FUNCTION: char** smoke_methodNames ( Smoke* s ) ;

FUNCTION: Index smoke_numTypes ( Smoke* s ) ;
FUNCTION: Index smoke_numClasses ( Smoke* s ) ;
FUNCTION: Index smoke_numMethods ( Smoke* s ) ;
FUNCTION: Index smoke_numMethodMaps ( Smoke* s ) ;
FUNCTION: Index smoke_numMethodNames ( Smoke* s ) ;

FUNCTION: ModuleIndex smoke_findClass ( Smoke* s, char* c ) ;
FUNCTION: ModuleIndex smoke_findMethod ( Smoke* s, char* c, char* name ) ;

Annotation: test.factor

Author: jedahu
Mode: factor
Date: Thu, 30 Apr 2009 22:45:26
Plain Text |
USING: smoke.ffi alien alien.c-types ;

init_qt_smoke
qt_smoke "QApplication" smoke_findClass
[ ModuleIndex-index ] [ ModuleIndex-smoke smoke_classes ] bi
[ "Class" heap-size * ] dip <displaced-alien>
"Class" heap-size memory>byte-array
Class-parents .

! Should print "41". Does on mac ppc, but not 64 bit linux

New Annotation

Summary:
Author:
Mode:
Body: