1, Q:為什么沒有用Luaplus或是其他的Binder?
A: nice question! Luaplus不能滿足我在linux下使用,其他的太龐大,我需要一個輕量級的。
2,Q:是原創(chuàng)嗎?
A:NO, thanks to Matthew Harmon
matt@matthewharmon.com,我按照自己的需求做了封裝。
3,Q:它的優(yōu)點是什么?
A:主要是它簡單,基本能滿足和C/C++交互的需求。它使用了lua_newthread來管理每一個腳本(性能有問題嗎?)。它支持
事件的resume,另外把LuaDebugger也封裝進來了,方便調(diào)試。
貼下接口頭文件:
#ifndef ILUAENGINE_H
#define ILUAENGINE_H

#define GTC_LP 0x0000 // 指針
#define GTC_INT 0x0001 // 整型
#define GTC_DOUBLE 0x0002 // 浮點型
#define GTC_STRING 0x0003 // 字符串

// 腳本數(shù)據(jù)類型定義
enum


{
SD_NUMBER = 0, // 數(shù)字類型
SD_STRING, // 字符串類型
SD_TABLE, //表
};

struct SSDTable


{
int nNum;
void* pValue;
};

// 腳本參數(shù)對象
struct SScriptParamObj


{
int nType; // 參數(shù)類型, SD_NUMBER 或者 SD_STRING

union UScriptParam // 參數(shù)值

{
int nNumber; // 數(shù)字
char szString[64]; // 字符串
SSDTable stTable;

} unValue;

SScriptParamObj()

{
memset(this, 0, sizeof(*this));
}

void operator = (int nValue)

{
nType = SD_NUMBER;
unValue.nNumber = nValue;
}

void operator = (char *str)

{
nType = SD_STRING;
unValue.szString[0] = 0;

if (str != NULL)

{
strncpy(unValue.szString, str, sizeof(unValue.szString));
}
}

void operator = ( SSDTable pT )

{
nType = SD_TABLE;
unValue.stTable.nNum = pT.nNum;
unValue.stTable.pValue = (void *)pT.pValue;
}

};

struct ILuaScript


{

/**//*
* @Param: szFileName - 腳本文件名
* @Return: NULL
* @Description: 調(diào)用一個腳本
*/
virtual bool CallFile(const char *szFileName) = 0;

/**//*
* @Param: szFuncName - 函數(shù)名 pIn, nInNum - 輸入?yún)?shù)列表指針以及個數(shù)
* @Return: pRet, nRetNum - 返回參數(shù)列表指針以及個數(shù)
* @Description: 調(diào)用一個函數(shù)
*/
virtual bool CallFunction(const char *szFuncName, SScriptParamObj *pIn,
int nInNum, SScriptParamObj *pRet, int nRetNum) = 0;

/**//*
* @Param: szString - 字符串指針
* @Return: NULL
* @Description: 調(diào)用一個字符串
*/
virtual bool CallString(const char *szString) = 0;


/**//*
* @Param: NULL
* @Return: NULL
* @Description: NULL
*/
virtual void ShowLuaCallStack() = 0;
};

struct ILuaManager


{

/**//*
* @Param: NULL
* @Return: NULL
* @Description: NULL
*/
virtual bool InitManager(IGameWorld* pGameWorld) = 0;

/**//*
* @Param: NULL
* @Return: NULL
* @Description: NULL
*/
virtual ILuaScript* CreateScript() = 0;

/**//*
* @Param: NULL
* @Return: NULL
* @Description: NULL
*/
virtual void Update(float fElapse) = 0;

/**//*
* @Param: NULL
* @Return: NULL
* @Description: 注意如果是自己卸載一個script,請自己
手工管理這個script的指針,manager析構(gòu)
的時候,會自動析構(gòu)所有的script
*/
virtual void UnlinkScript(ILuaScript* pScript) = 0;

/**//*
* @Param: NULL
* @Return: NULL
* @Description: NULL
*/
virtual ILuaScript* GetScript(const char* szScriptName) = 0;

/**//*
* @Param: NULL
* @Return: NULL
* @Description: NULL
*/
virtual void Release() = 0;
};
#endif
另外,還有一個高手寫的binder,針對c++的object做了很好的封裝,但我沒有采用,因為我想要靈活一點的。
鏈接在下面,大家可以對比一下,給出評論
http://www.codeproject.com/KB/cpp/luaincpp.aspx本文的下載文件