记第一次lua和C互相调用的例子
(以下的内容参考别人的例子,特此声明)在写程序之前,需要安装lua的环境
在终端输入命令:
<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>安装好之后,输入lua -v,查看lua版本:
建议:输入ln -s lua5.1 lua,做一个软链接,以后运行lua的时候,就会运行lua5.1
第一部分:C语言调用lua中的函数(ubuntu)
1.先写个add.c文件
2.再写一个我们将要调用的lua函数(add.lua)
3.最后,使用命令:gcc -o add add.c -I /usr/include/lua5.1 -llua5.1,生成add可执行文件,如图:
第二部分:lua调用C语言的函数(ubuntu)
1.写一个hello.lua文件
2.再写一个power_lua.c文件
3.运行命令:gcc-Wall -shared -fPIC -o power.so -I/usr/include/lua5.1 power_lua.c
在当前目录中会看到power.so文件
4.最后,激动人心的时刻到了!
运行:lua hello.lua,结果如下:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use
