📄 tstlua.cpp
字号:
// tstlua.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
/* the Lua interpreter */
lua_State* L;
static int average(lua_State *L)
{
/* get number of arguments */
int n = lua_gettop(L);
double sum = 0;
int i;
/* loop through each argument */
for (i = 1; i <= n; i++)
{
/* total the arguments */
sum += lua_tonumber(L, i);
}
/* push the average */
lua_pushnumber(L, sum / n);
/* push the sum */
lua_pushnumber(L, sum);
/* return the number of results */
return 2;
}
typedef unsigned long DWORD;
int g_iCtestCount = 0;
class CTest
{
public:
CTest(void)
{
m_index = g_iCtestCount;
g_iCtestCount++;
}
~CTest(void)
{
printf("%d %s", m_index, "is bDeled!");
}
void Tf()
{
char caOt[20];
sprintf(caOt, "CTest %d bCalled\r\n", m_index);
printf("%s",caOt);
}
int m_index;
};
#define DEFINE_CLASS(tClass)\
static int new##tClass(lua_State *L) \
{ \
tClass* pT = new tClass; \
lua_pushnumber(L, (DWORD)pT); \
return 1; \
} \
#define DELETE_CLASS(tClass) \
static int del##tClass(lua_State* L) \
{ \
DWORD dwCl = (DWORD)lua_tonumber(L, 1); \
if (dwCl) \
delete ((tClass*)dwCl); \
return 0; \
} \
#define DEFINE_CLASS_FUNC(tClass, tFunc) \
static int tClass##tFunc(lua_State* L) \
{ \
DWORD dwCl = (DWORD)lua_tonumber(L, 1); \
((tClass*)dwCl)->Tf(); \
return 0; \
} \
DEFINE_CLASS(CTest);
DELETE_CLASS(CTest);
DEFINE_CLASS_FUNC(CTest, Tf);
//static int Tf(lua_State *L)
//{
// DWORD dwCl = (DWORD)lua_tonumber(L, 1);
// ((CTest*)dwCl)->Tf();
// return 0;
//}
int _tmain(int argc, _TCHAR* argv[])
{
/* initialize Lua */
int a;
L = lua_open();
/* load Lua base libraries */
luaL_openlibs(L);
/* register our function */
//lua_register(L, "newCTest", newCTest);
//lua_register(L, "delCTest", delCTest);
//lua_register(L, "CTestTf", CTestTf);
/* run the script */
luaL_dofile(L, "f:\\init.lua");
lua_pushstring(L,"scripts\\sys\\");
lua_setglobal(L, "sysDir");
lua_getglobal(L, "sysDir");
char* z = (char*)lua_tostring(L, 1);
lua_pop(L, 1);
/* cleanup Lua */
lua_close(L);
/* pause */
printf( "Press enter to exit…" );
getchar();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -