summaryrefslogtreecommitdiffstats
path: root/squirrel_3_0_1_stable/sqplus/SquirrelBindingsUtilsWin32.h
blob: 3f335842295f9278b8aa8b6213632a3a0c58bde4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef SQUIRREL_BINDINGS_UTILS_WIN32_H
#define SQUIRREL_BINDINGS_UTILS_WIN32_H

#ifndef _INC_WINDOWS
#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
#endif
#ifndef __IUnknown_INTERFACE_DEFINED__
#include <unknwn.h>
#endif

#ifndef SQUIRREL_BINDINGS_UTILS_H
#include "SquirrelBindingsUtils.h"
#endif

#define _DECLARE_REFCOUNTED_NEW(cppclass,classname) \
	SquirrelObject new_##classname(cppclass *ptr) { \
		if(CreateRefCountedInstance(SquirrelVM::GetVMPtr(),_SC(#classname),ptr)) { \
			HSQOBJECT o; \
			sq_getstackobj(SquirrelVM::GetVMPtr(),-1,&o); \
			SquirrelObject tmp = o; \
			sq_pop(SquirrelVM::GetVMPtr(),1); \
			return tmp; \
		} \
		return SquirrelObject() ; \
	}

#define _RETURN_REFCOUNTED_INSTANCE(classname,ptr) \
	if(!CreateRefCountedInstance(SquirrelVM::GetVMPtr(),_SC(#classname),ptr)) { \
		return sa.ThrowError(_SC("cannot create the class instance")); \
	} \
	return 1;

BOOL CreateRefCountedInstance(HSQUIRRELVM v,const SQChar *classname,IUnknown *pRC);
BOOL CreateRefCountedInstanceChached(HSQUIRRELVM v,const SQChar *classname,IUnknown *pRC);
int refcounted_release_hook(SQUserPointer p, int size);
int construct_RefCounted(IUnknown *p);

#endif // SQUIRREL_BINDINGS_UTILS_WIN32_H