Detailed description of LUA and Delphi applications

Source: Internet
Author: User

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:

 
 
  1. var L: Plua_State;  
  2. L := lua_open; 

2. After running, you must turn off:

 
 
  1. lua_close(L); 

3. Add a method in Lua, such as adding the Print ("mrlong") method to the Lua script.

 
 
  1. Function LuaPrint (L: Plua_State): Integer; cdecl;
  2. Var
  3. I, N: Integer;
  4. Egin
  5. // LuaShowStack ');
  6.  
  7. N: = lua_gettop (L );
  8. For I: = 1 to N do
  9. ShowMessage (lua_tostring (L, I ));
  10. Result: = 0;
  11. 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.