Remember the first example of Lua and C calling each other
(The following content refers to other people’s examples, hereby declare)
Before writing a program, you need to install the Lua environment
Enter the command in the terminal:
<ol style="margin:0 1px 0 0px;padding-left:40px;" start="1" class="dp-css"><li>sudo apt-get install lua5.1<br /> </li><li>sudo apt-get install lua5.1-0-dev(注意:安装这个东西是为了lua的一些头文件和库文件路径使用) </li></ol>
After installation, enter lua -v to check the lua version:
Suggestion: Enter ln -s lua5.1 lua to make a soft link. When running lua in the future, it will run lua5.1
Part 1: C language calls functions in lua (ubuntu)
1. First write an add.c file
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 add executable file, as shown in the figure:
Part 2: lua calls C language function (ubuntu)
1. Write a hello.lua file
2. Write another power_lua.c file
3. Run the 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 has arrived!
Run: lua hello.lua, the results are as follows:
http://www.bkjia.com/PHPjc/1115819.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1115819.htmlTechArticleRemember the first example of Lua and C calling each other (the following content refers to other people's examples, hereby declare) in Before writing a program, you need to install the Lua environment and enter the command in the terminal: sudo apt-get i...