Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding Lua in C++

Tags:

I've been trying to embed lua in a c++ application but to no avail since the compiler complains about "lua_open".I'm using Lua 5.2.

I found alot of articles claiming that lua_open() was replaced in the fifth version but none of them mentioned with what.

Here's the code I am trying to compile

extern "C" { #include "../lua/lua.h" #include "../lua/lualib.h" #include "../lua/lauxlib.h" }  int main() {     int s=0;      lua_State *L = lua_open();     // load the libs     luaL_openlibs(L);     luaL_dofile(L,"example.lua");     printf("\nDone!\n");     lua_close(L);      return 0; } 
like image 861
NT_SYSTEM Avatar asked Dec 18 '11 15:12

NT_SYSTEM


People also ask

Can Lua be compiled to C?

Lua is implemented in pure ANSI C and compiles unmodified in all known platforms. All you need to build Lua is an ANSI C compiler (gcc and clang are a popular ones). Lua also compiles cleanly as C++.

What is embedded Lua?

Embedded Lua (eLua) is a scripting language designed for embedded systems. It is powerful but small enough to run on microcontroller platforms. Anton Mikanovich. Very often while developing complex systems, engineers have to greatly simplify the task of writing final user space applications.

Is Lua an embedded language?

Lua is a general-purpose embedded programming language designed to support procedural programming with data-description facilities.

Is C and Lua the same?

Lua is compiled into byte code (not to be confused with machine code.) and executed by a software interpreter at runtime. C is a compiled language that is compiled into machine code from source code and executed by hardware.


1 Answers

Indeed, the lua_open function is not mentioned in the lua 5.2 reference manual

A lua_State is constructed with lua_newstate, and you can use luaL_newstate from lauxlib.h

A faster way to get the answers to such question is to look into the Lua 5.2 source code (which I just did).

like image 127
Basile Starynkevitch Avatar answered Oct 30 '22 23:10

Basile Starynkevitch