⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 luaddx.cpp

📁 一个2D电磁场FEM计算的VC++源程序
💻 CPP
字号:
#include "stdafx.h"
#include "lua.h"

#undef DDX_Text

extern lua_State * lua;

void Lua_DDX_Text(CDataExchange *pDX, int nIDC, int &x)
{
	// if initializing things, just call DDX_Text in the 
	// usual way...
	if (pDX->m_bSaveAndValidate==FALSE) 
		DDX_Text(pDX, nIDC, x);
	// otherwise, side-track things by sending the contents
	// to Lua, processing them, and then stripping off the results;
	else{
		CString tolua;
		int i,k;
		DDX_Text(pDX, nIDC, tolua);
		tolua="return " + tolua;
		i=lua_gettop(lua);
		lua_dostring(lua,tolua);
		k=lua_gettop(lua);
		if (i!=k){
			tolua=lua_tostring(lua,-1);
			if (tolua.GetLength()==0){
				AfxMessageBox("Input does not evaluate to a numerical value");
				pDX->Fail();
			}
			else x=(int)lua_tonumber(lua,-1);
		}
		else pDX->Fail();
	}
}

void Lua_DDX_Text(CDataExchange* pDX, int nIDC, CString& value)
{
	DDX_Text(pDX, nIDC, value);	
}

void Lua_DDX_Text(CDataExchange *pDX, int nIDC, double &x)
{
	// if initializing things, just call DDX_Text in the 
	// usual way...
	if (pDX->m_bSaveAndValidate==FALSE) 
		DDX_Text(pDX, nIDC, x);
	// otherwise, side-track things by sending the contents
	// to Lua, processing them, and then stripping off the results;
	else{
		CString tolua;
		int i,k;
		DDX_Text(pDX, nIDC, tolua);
		tolua="return " + tolua;
		i=lua_gettop(lua);
		lua_dostring(lua,tolua);
		k=lua_gettop(lua);
		if (i!=k){
			tolua=lua_tostring(lua,-1);
			if (tolua.GetLength()==0){
				AfxMessageBox("Input does not evaluate to a numerical value");
				pDX->Fail();
			}
			else x=lua_tonumber(lua,-1);
		}
		else pDX->Fail();
	}
		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -