vector_1.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <iostream>
  2. #include "gmThread.h"
  3. class Vector
  4. {
  5. public:
  6. Vector() : x(0), y(0), z(0) { }
  7. Vector( float a_x, float a_y, float a_z ) : x(a_x), y(a_y), z(a_z) { }
  8. float x, y, z;
  9. };
  10. namespace gmVector
  11. {
  12. // Declare a type ID
  13. gmType Type = GM_NULL;
  14. /// Entry point for the library; this is effectively the constructor
  15. int GM_CDECL libentry( gmThread *a_thread )
  16. {
  17. std::cout << "Vector:: libentry called from script\n";
  18. Vector *p = new Vector();
  19. a_thread->PushNewUser( p, Type );
  20. return GM_EXCEPTION;
  21. }
  22. // Library entry point; this defines the constructor of the type
  23. gmFunctionEntry lib[] =
  24. {
  25. { "Vector", libentry }
  26. };
  27. void BindLib( gmMachine *a_machine )
  28. {
  29. // Register one function (the entry point)
  30. a_machine->RegisterLibrary( lib, 1 );
  31. Type = a_machine->CreateUserType( lib[0].m_name );
  32. }
  33. }; // end namespace gmVector
  34. int main()
  35. {
  36. gmMachine gm;
  37. // Bind the type
  38. gmVector::BindLib( &gm );
  39. // A simple test
  40. gm.ExecuteString("v = Vector();" );
  41. return 0;
  42. }