Remember the first time LUA and C call each other example
(The following is a reference to other people's examples, hereby stated)
Before writing a program, you need to install the LUA environment
In the terminal input command:
- sudo apt-get install lua5.1
After installation, enter Lua-v to view the LUA version:
Recommendation: Enter Ln-s lua5.1 lua, make a soft link, and run Lua at a later time lua5.1
Part I: The C language calls Lua functions (Ubuntu)
1. Write a ADD.C file first
2. Write another Lua function (Add.lua) that we will call
3. Finally, use the command: Gcc-o add add.c-i/usr/include/lua5.1-llua5.1, generate the Add executable file,
Part II: LUA calls C-language functions (Ubuntu)
1. Write a Hello.lua file
2. Write a power_lua.c file again
3. Run command: Gcc-wall-shared-fpic-o power.so-i/usr/include/lua5.1 power_lua.c
You will see the power.so file in the current directory
4. Finally, the exciting moment is up!
Run: Lua Hello.lua, the results are as follows:
http://www.bkjia.com/PHPjc/1115819.html www.bkjia.com true http://www.bkjia.com/PHPjc/1115819.html techarticle Remember the first time Lua and C invoke each other example (the following reference to other people's examples, hereby stated) before writing the program, you need to install the LUA environment in the terminal Input command: sudo apt-get i ...