Call Lua code in C

Source: Internet
Author: User


This program reads the content from the terminal and then runs according to the Lua block.

# Include <stdio. h> # include <string. h> # include "Lua. H "# include" lauxlib. H "# include" lualib. H "int main () {char buff [1024]; int error; memset (buff, 0, sizeof (buff); lua_state * l = lual_newstate (); // open Lua lual_openlibs (l); // open the standard lib while (fgets (buff, sizeof (buff), stdin )! = NULL) {// If success, return 0 error = lual_loadbuffer (L, buff, strlen (buff), "line") | lua_pcall (L, 0, 0, 0); If (error) {fprintf (stderr, "% s", lua_tostring (L,-1); lua_pop (L, 1 ); // pop the err MSG from Stack} lua_close (l); Return 0 ;}



Compilation error: Lua. H: No file or directory
Locate Lua. h does not have the corresponding header file under the corresponding include directory. You need to download and install liblua5.2-Dev, and then sudo updatedb; locate Lua. H will find it.
/Home/vonzhou/redis-2.6/deps/Lua/doc/lua.html
/Home/vonzhou/redis-2.6/deps/Lua/etc/Lua. HPP
/Home/vonzhou/redis-2.6/deps/Lua/src/Lua. h
/Usr/include/lua5.2/Lua. h
/Usr/include/lua5.2/Lua. HPP
/Usr/src/linux-headers-3.2.0-23-generic/include/config/SCSI/DH/alua. h

Specify the path during compilation, for example,-I/usr/include/lua5.2/or add full include <lua5.2/Lua. h> During the include operation. In addition, the link to the lua5.2 library is displayed. Otherwise, other errors such as undefined reference to 'lual _ newstate' may occur.



Call Lua code in C

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.