詳解關于LUA與Delphi應用
關于LUA與Delphi應用是本文要介紹的內容,主要是來了解并學習lua的應用,具體內容來看本文詳解。LUA可到 Http://www.Lua.org 內下載Lua4Delphi 包。
Lua基本的用法.
1、打開Lua:
- var L: Plua_State;
- L := lua_open;
2、運行后,必須關掉:
- lua_close(L);
3、在Lua內增加方法, 如 Lua腳本內增加 Print("mrlong") 的Print方法時,必須這樣定義
- 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、這時在打開lua后,注冊方法: LuaRegister(L, 'print', LuaPrint);
5、加載腳本: LuaLoadBuffer(L, memCode.Text, 'code');
6、運行Lua的腳本: LuaPCall(L, 0, 0, 0);
7、取出注冊方法的參數: 如右Lua腳本了print("mrlong"); 這時我要取出mrlong 時,則采用。
S:= lua_tostring(L, 1); //注意這地方是從1開始,不是0與Delphi與C/C++都不一樣。\
if (lua_gettop(L) <> 2) then//其中lua_gettop(L) 是取出參數的個數據
luaL_error(L, '參數個數出錯');
小結:詳解關于LUA與Delphi應用的內容介紹完了,希望通過本文的學習能對你有所幫助!