// stdafx.h : 자주 사용하지만 자주 변경되지는 않는
// 표준 시스템 포함 파일 및 프로젝트 관련 포함 파일이
// 들어 있는 포함 파일입니다.
//
#pragma once
#ifndef _WIN32_WINNT // Windows XP 이상에서만 기능을 사용할 수 있습니다.
#define _WIN32_WINNT 0x0501 // 다른 버전의 Windows에 맞도록 적합한 값으로 변경해 주십시오.
#endif
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <boost/python/pure_virtual.hpp>
#include <boost/python/return_value_policy.hpp>
#include <boost/python/manage_new_object.hpp>
#include <boost/python/def.hpp>
// boost_python.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
class base
{
public:
base(const char* name) : m_name(name)
{}
virtual ~base()
{
puts("del base");
}
void func()
{
}
virtual void pure_func() = 0;
std::string m_name;
};
class derived : public base
{
public:
derived(const char* name) : base(name)
{
}
virtual ~derived()
{
puts("del derived");
}
void pure_func()
{
puts(m_name.c_str());
}
};
base* Make(const char* name)
{
return new derived(name);
}
using namespace boost::python;
BOOST_PYTHON_MODULE(test)
{
class_<base, boost::noncopyable>("base", no_init)
.def("pure_func", pure_virtual(&base::pure_func))
;
class_<derived, bases<base> >("derived", init<const char*>())
.def("pure_func", &derived::pure_func)
;
def("Make", Make, return_value_policy<manage_new_object>());
}
int _tmain(int argc, _TCHAR* argv[])
{
Py_Initialize();
inittest();
PyRun_SimpleString("import test;obj = test.Make('abc');obj.pure_func()");
Py_Finalize();
return 0;
}


python 을 좋아하는 게임 프로그래머