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

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

// 腳本數據類型定義
enum


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

struct SSDTable


{
int nNum;
void* pValue;
};

// 腳本參數對象
struct SScriptParamObj


{
int nType; // 參數類型, SD_NUMBER 或者 SD_STRING

union UScriptParam // 參數值

{
int nNumber; // 數字
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: 調用一個腳本
*/
virtual bool CallFile(const char *szFileName) = 0;

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

/**//*
* @Param: szString - 字符串指針
* @Return: NULL
* @Description: 調用一個字符串
*/
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析構
的時候,會自動析構所有的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本文的下載文件