Public feed
#528806
// gmtest.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "gm/gmConfig_p.h"#include "gm/gmConfig.h"#include "gm/gmMachine.h"#include "gm/gmCall.h"gmType mytype;class Unit{private: int me;public: void SetMe(int m) { me = m; } int GetMe() { return me; } static int GM_CDECL Unit_GetMe(gmThread * a_thread) { GM_CHECK_NUM_PARAMS(0); GM_ASSERT(a_thread->GetThis()->m_type == mytype); Unit * ptr = (Unit*)a_thread->ThisUser(); int res = ptr->GetMe(); a_thread->PushInt(res); return GM_OK; }};int GM_CDECL int _tmain(int argc, _TCHAR* argv[]){ Unit me; me.SetMe(100); gmMachine * m = new gmMachine(); mytype = m->CreateUserType("Unit"); gmFunctionEntry e; e.m_function = &Unit::Unit_GetMe; e.m_name = "GetMe"; m->RegisterTypeLibrary(mytype, &e, 1); gmVariable t; gmUserObject * mu = m->AllocUserObject(&me, mytype); m->AddCPPOwnedGMObject(mu); t.SetUser(mu); /* load file */ FILE * f = fopen("test.gm", "rb"); int size; fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); char * str = new char[size+1]; fread(str, size, 1, f); str[size] = 0; fclose(f); int tid; int errors = m->ExecuteString(str, &tid, true, "test.gm"); if(errors) { bool first = true; const char * message; while((message = m->GetLog().GetEntry(first))) printf("Error: %s\n", message); } gmCall c; int ret; bool r ; if(c.BeginGlobalFunction(m, "TestFunc", t, false)) { c.End(); r = c.GetReturnedInt(ret); } return 0;}