AboutLUAAndDelphiThe application is the content to be introduced in this article, mainly to understand and learnLuaFor more information, see this article. You can download the Lua4Delphi package from Http: // www.Lua.org.
Basic usage of Lua.
1. Open Lua:
- var L: Plua_State;
- L := lua_open;
2. After running, you must turn off:
- lua_close(L);
3. Add a method in Lua, such as adding the Print ("mrlong") method to the Lua script.
- Function LuaPrint (L: Plua_State): Integer; cdecl;
- Var
- I, N: Integer;
- Egin
- // LuaShowStack ');
-
- N: = lua_gettop (L );
- For I: = 1 to N do
- ShowMessage (lua_tostring (L, I ));
- Result: = 0;
- End;
4. OpenLuaThen, the registration method is: LuaRegister (L, 'print ', LuaPrint );
5. Load the Script: LuaLoadBuffer (L, memCode. Text, 'code ');
6. RunLuaScript: LuaPCall (L, 0, 0, 0 );
7. Retrieve the parameters of the registration method. For example, print ("mrlong") is used in the right Lua script.
S: = lua_tostring (L, 1); // note that this is from 1, not both 0 and Delphi and C/C ++. \
If (lua_gettop (L) <> 2) then // Where lua_gettop (L) is the data of the retrieved Parameter
LuaL_error (L, 'number of parameter errors ');
Summary: DetailsLUAAndDelphiThe application content has been introduced. I hope this article will help you!