Sha256: b425acbb27c8b5154e25d93d09744d9fdcf0ca2363be0c348c3c909276afec50

Contents?: true

Size: 902 Bytes

Versions: 10

Compression:

Stored size: 902 Bytes

Contents

/**
 * Code to wrap and handle function callbacks by exposing them
 * into Ruby as block arguments
 */
#ifndef __FUNCTION_POINTERS_H__
#define __FUNCTION_POINTERS_H__

namespace function_pointers {

  // One that takes no argument, no return
  typedef void(*Callback) (void);
  Callback emptyCallback;

  void setCallback(Callback cb) { emptyCallback = cb; }
  void callCallback() { emptyCallback(); }

  // With an argument, no return
  typedef void(*ArgCallback) (int num);
  ArgCallback argumentCallback;

  void setCallbackWithArgs(ArgCallback cb) { argumentCallback = cb; }
  void callCallbackWithArgs(int in) { argumentCallback(in); }

  // With argument and returns a value
  typedef int(*ReturnCallback) (int num);
  ReturnCallback returnCallback;

  void setCallbackReturns(ReturnCallback cb) { returnCallback = cb; }
  int callCallbackReturns(int in) { return returnCallback(in); }
}

#endif

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rbplusplus-1.4.0 test/headers/function_pointers.h
rbplusplus-1.3.0 test/headers/function_pointers.h
rbplusplus-1.2.1 test/headers/function_pointers.h
rbplusplus-1.2.0 test/headers/function_pointers.h
rbplusplus-1.1.0 test/headers/function_pointers.h
rbplusplus-1.0.3 test/headers/function_pointers.h
rbplusplus-1.0.1 test/headers/function_pointers.h
rbplusplus-1.0 test/headers/function_pointers.h
rbplusplus-0.9.1 test/headers/function_pointers.h
rbplusplus-0.9 test/headers/function_pointers.h