首先建立一个export_class的DLL工程,然后建立一个TestClass测试类
TestClass.h
#pragma once
#include <string>
#include <iostream>
using namespace std;

class TestClass
;
TestClass.cpp
#include "TestClass.h"

TestClass TestClass::m_Singleton = TestClass("default string");

TestClass::TestClass(string s)
}
export_class.cpp
// export_class.cpp : Defines the entry point for the DLL application.
#include <luabind/luabind.hpp>

extern "C"
}
脚本如下:
require "export_class"

g_print()

--testClass = Singleton()
testClass = TestClass("haha~~")


if testClass == nil then
print "testClass is a null value!"
else
testClass:Print()
end
脚本运行结果:
现在还有一点问题,就是用Singleton的静态成员函数调用后再Print有问题,目前我也没有搞明白是怎么回事。太奇怪了。。。。
TestClass.h
TestClass.cpp
export_class.cpp
脚本如下:
脚本运行结果:
| >lua -e "io.stdout:setvbuf 'no'" "main.lua" TestClass::TestClass() hello, Eric Xiang! TestClass::TestClass() haha~~ >Exit co |
现在还有一点问题,就是用Singleton的静态成员函数调用后再Print有问题,目前我也没有搞明白是怎么回事。太奇怪了。。。。