Demo of the basic Lua type

Source: Internet
Author: User

The following is a plug-in for executing the Lua script in C language. You can drag the Lua file to the EXE to run it, or bind the 1.lua file in the current directory by default.

Header file and Lua. the location of LIB depends on your own situation, conio. the H header file is only used to allow getch () to read arbitrary characters after each execution and is not displayed. conio can be removed if conio cannot be compiled. h. Replace getch () with getchar ()

# Include <stdio. h> # include <conio. h> extern "C" {# include "G: \ library \ Lua \ lua-5.2.3 \ SRC \ Lua. H "# include" G: \ library \ Lua \ lua-5.2.3 \ SRC \ lualib. H "# include" G: \ library \ Lua \ lua-5.2.3 \ SRC \ lauxlib. H "} # pragma comment (Lib," C: \ Lua. lib ") int main (INT argc, char * argv []) {char * P; If (argc> = 2) {P = argv [1];} else {P = "1.lua";} printf (" binding: % s \ n ", P); While (1) {lua_state * l = lual_newstate (); lual_openlibs (L ); lual_do File (L, P); lua_close (l); printf ("execution completed! \ N "); getch ();} return 0 ;}

1. Some basic demos in The Lua File

B = 10 -- the variable exists when the value is not nil. Print (B) B = nilprint (B) print ("type:") print (type ('hello ')) print (type (10*3) print (type (1.0*2.3) print (type (print) print (type (true) print (type (NiL )) print (type (x) print ('string: ') page = [[# include <stdio. h> int main () {return 0 ;}] -- stores string Io. write (PAGE) print ('10' * 5) -- convert string to print (1 + 8) -- convert number to stringprint ('abc '.. 'de') -- Link string print ('enter a line and convert it to a number') line = Io. read () n = tonumber (line) if n = nil thenprint (line .. 'Cannot be converted to number') error (line .. 'cannot be converted to number') -- error will directly end running elseprint ('after conversion :'.. n) endprint (tostring (10) = '10') print (10 .. ''= '10 ')


Demo of the basic Lua type

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.