詳解關(guān)于LUA與Delphi應(yīng)用
關(guān)于LUA與Delphi應(yīng)用是本文要介紹的內(nèi)容,主要是來了解并學(xué)習(xí)lua的應(yīng)用,具體內(nèi)容來看本文詳解。LUA可到 Http://www.Lua.org 內(nèi)下載Lua4Delphi 包。
Lua基本的用法.
1、打開Lua:
- var L: Plua_State;
- L := lua_open;
2、運(yùn)行后,必須關(guān)掉:
- lua_close(L);
3、在Lua內(nèi)增加方法, 如 Lua腳本內(nèi)增加 Print("mrlong") 的Print方法時(shí),必須這樣定義
- function LuaPrint(L: Plua_State): Integer; cdecl;
- var
- I, N: Integer;
- egin
- //LuaShowStack(L, '僨僶僢僌梡:LuaPrint 偵搉偝傟偨堷悢');
- N := lua_gettop(L);
- for I := 1 to N do
- ShowMessage(lua_tostring(L, I));
- Result := 0;
- end;
4、這時(shí)在打開lua后,注冊(cè)方法: LuaRegister(L, 'print', LuaPrint);
5、加載腳本: LuaLoadBuffer(L, memCode.Text, 'code');
6、運(yùn)行Lua的腳本: LuaPCall(L, 0, 0, 0);
7、取出注冊(cè)方法的參數(shù): 如右Lua腳本了print("mrlong"); 這時(shí)我要取出mrlong 時(shí),則采用。
S:= lua_tostring(L, 1); //注意這地方是從1開始,不是0與Delphi與C/C++都不一樣。\
if (lua_gettop(L) <> 2) then//其中l(wèi)ua_gettop(L) 是取出參數(shù)的個(gè)數(shù)據(jù)
luaL_error(L, '參數(shù)個(gè)數(shù)出錯(cuò)');
小結(jié):詳解關(guān)于LUA與Delphi應(yīng)用的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對(duì)你有所幫助!