今天玩了一把腳本,玩完的感覺(jué)是真的好稀飯腳本啊。
1、編譯lua注意的總結(jié)
lua的項(xiàng)目默認(rèn)是用在linux上用bjam編譯,這點(diǎn)很爽。如果要在windows上編譯,有兩種方式:
a)用vs的命令行進(jìn)入lua根目錄,執(zhí)行“etc\luavs.bat”即可,執(zhí)行成功后會(huì)在src目錄下生成以下三個(gè)文件:
lua.exe
lua.lib
lua.dll
b)手動(dòng)建立項(xiàng)目文件
自己新建一個(gè)靜態(tài)庫(kù)或動(dòng)態(tài)庫(kù),將根目錄下的src文件夾下所有文件拉進(jìn)來(lái),刪除lua.c\luac.c這2個(gè)目錄即可。注意需要設(shè)置編譯選項(xiàng)中的字符集為“使用多字節(jié)字符集”,不然lua庫(kù)運(yùn)行時(shí)初始化會(huì)崩潰。
今天先用的第二個(gè)方式編譯,一切正常,但是運(yùn)行的時(shí)候發(fā)現(xiàn)初始化lua庫(kù)的時(shí)候程序崩潰,跟蹤發(fā)現(xiàn)問(wèn)題出在lua_lib這個(gè)函數(shù)中,不是很得要領(lǐng)。后來(lái)嘗試用第一種方式,才沒(méi)有崩潰。比較發(fā)現(xiàn)需要設(shè)置編譯選項(xiàng)中的字符集為“使用多字節(jié)字符集”。
luavs.bat內(nèi)容如下:
cd src
cl /O2 /W3 /c /DLUA_BUILD_AS_DLL l*.c
del lua.obj luac.obj
link /DLL /out:lua51.dll l*.obj
cl /O2 /W3 /c /DLUA_BUILD_AS_DLL lua.c
link /out:lua.exe lua.obj lua51.lib
cd ..
當(dāng)然手動(dòng)編譯為dll的時(shí)候需要設(shè)置編譯選項(xiàng)“LUA_BUILD_AS_DLL ”
2.編譯luabind
編譯luabind的時(shí)候,沒(méi)耐心看官方說(shuō)明文檔,直接拉到vs中編譯。當(dāng)然還是看了下源文件的bjam的相關(guān)文件,沒(méi)有發(fā)現(xiàn)有什么特殊的地方需要注意。所以直接編譯,直接通過(guò)。
總結(jié)下,碰到這些開(kāi)源項(xiàng)目沒(méi)有vs工程文件,編譯說(shuō)明不像ogre那么全,第一感覺(jué)就是怕麻煩。其實(shí)那些開(kāi)源社區(qū)的貢獻(xiàn)者是非常聰明的人,并不會(huì)給我添多少麻煩,如果我非常周折還是有編譯問(wèn)題,說(shuō)明我走彎路了,得靜下來(lái)考慮。
3.luabind、luaplus、tolua++。。。
沒(méi)有找到比較文檔,中文有說(shuō)luabind需要boost所以如何如何的,被我無(wú)視掉。所以?xún)?yōu)劣再說(shuō)了。luabind是官方一個(gè)wiki中介紹的。luplus是武俠使用的,tolua是cegui使用的。
4.腳本賞析
這是腳步:


-- Lua script for test program.

print( 'Hello from LUA!' )

app = getApplication()

app:setBackgroundColour( ColourValue( 0, 0, .25 ) )

camera = app:getCamera()

camera:setPosition( Vector3(0,100,500) )

camera:lookAt( Vector3(0,0,0) )

camera:setNearClipDistance( 5 )

e = app:createEntity( 'Ninja', 'ninja.mesh' )

e:setDisplaySkeleton( true )

rootNode = app:getRootNode()

child = rootNode:createChildSceneNode( 'NinjaNode' )

child:attachObject( e )

child:yaw( 180 )

child:setPosition( Vector3.ZERO )

e = app:createEntity( 'floor', 'floor' )

e:setMaterialName( 'Examples/GrassFloor' , 'Autodetect' )

child = rootNode:createChildSceneNode( 'FloorNode' )

child:attachObject( e )
這是綁定ogre函數(shù)的代碼:


void bindVector3( lua_State* L )


{
module(L)
[
class_<Vector3>( "Vector3" )
.def(tostring(self))
.def_readwrite( "x", &Vector3::x )
.def_readwrite( "y", &Vector3::y )
.def_readwrite( "z", &Vector3::z )
.def(constructor<>())
.def(constructor<Vector3&>())
.def(constructor<Real, Real, Real>())
.def("absDotProduct", &Vector3::absDotProduct)
.def("crossProduct", &Vector3::crossProduct )
.def("directionEquals", &Vector3::directionEquals )
.def("distance", &Vector3::distance )
.def("dotProduct", &Vector3::dotProduct )
.def("getRotationTo", &Vector3::getRotationTo )
.def("isZeroLength", &Vector3::isZeroLength )
.def("length", &Vector3::length )
.def("makeCeil", &Vector3::makeCeil )
.def("makeFloor", &Vector3::makeFloor )
.def("midPoint", &Vector3::midPoint )
.def("normalise", &Vector3::normalise )
.def("nornaliseCopy", &Vector3::normalisedCopy )
.def("perpendicular", &Vector3::perpendicular )
.def("positionCloses", &Vector3::positionCloses )
.def("positionEquals", &Vector3::positionEquals )
//.def("ptr", &Vector3::ptr )
.def("randomDeviant", &Vector3::randomDeviant )
.def("reflect", &Vector3::reflect )
.def("squaredDistance", &Vector3::squaredDistance )
.def("squaredLength", &Vector3::squaredLength )

// Operators

.def( self + other<Vector3>() )
.def( self - other<Vector3>() )
.def( self * other<Vector3>() )
.def( self * Real() )
];

LUA_CONST_START( Vector3 )
LUA_CONST( Vector3, ZERO);
LUA_CONST( Vector3, UNIT_X );
LUA_CONST( Vector3, UNIT_X);
LUA_CONST( Vector3, UNIT_Y);
LUA_CONST( Vector3, UNIT_Z);
LUA_CONST( Vector3, NEGATIVE_UNIT_X);
LUA_CONST( Vector3, NEGATIVE_UNIT_Y);
LUA_CONST( Vector3, NEGATIVE_UNIT_Z);
LUA_CONST( Vector3, UNIT_SCALE);
LUA_CONST_END;
}
編譯運(yùn)行后的結(jié)果: