- Lua (/ ˈ l uː ə / LOO-ə; from Portuguese: lua meaning moon) is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications. Lua is cross-platform, since the interpreter of compiled bytecode is written in ANSI C, and Lua has a relatively simple C API to embed it into applications.
- Finally, Lua-Terra can also be embedded in pre-existing applications by linking the application against libterra.a and using Terra’s C API. The interface is very similar to that of the Lua interpreter. A simple example initializes Terra and then runs code from the file specified in each argument.
This first edition was written for Lua 5.0. /mustek-gsmart-mini-3-drivers-for-mac-15266/. While still largely relevant for later versions, there are some differences.
The fourth edition targets Lua 5.3 and is available at Amazon and other bookstores.
By buying the book, you also help to support the Lua project.
|Programming in Lua|
|Part IV. The C APIChapter 24. An Overview of the C API|
24.1 – A First Example
C++ Lua Interface Tutorial
We will start this overview with a simple example of anapplication program:a stand-alone Lua interpreter.We can write a primitive stand-alone interpreter as follows:
WARNING: this code is for Lua 5.0.To run it in Lua 5.1,you must change the five calls
luaopen_*(L)to a single call to
luaL_openlibs(L).The header file
lua.h defines the basic functions provided by Lua.That includes functions to create a new Lua environment(such as
lua_open),to invoke Lua functions (such as
lua_pcall),to read and write global variables in the Lua environment,to register new functions to be called by Lua, and so on.Everything defined in
lua.h has the
The header file
lauxlib.h defines the functions providedby the auxiliary library (auxlib).All its definitions start with
luaL_loadbuffer).The auxiliary library uses the basic API provided by
lua.hto provide a higher abstraction level;all Lua standard libraries use the auxlib.The basic API strives for economy and orthogonality,whereas auxlib strives for practicality for common tasks.Of course, it is very easy for your program to create otherabstractions that it needs, too.Keep in mind that the auxlib has no access to the internals of Lua.It does its entire job through the official basic API.
The Lua library defines no global variables at all.It keeps all its state in the dynamic structure
lua_Stateand a pointer to this structure is passed as an argumentto all functions inside Lua.This implementation makes Lua reentrantand ready to be used in multithreaded code.
lua_open function creates a new environment (or state).When
lua_open creates a fresh environment,this environment contains no predefined functions,not even
lualib.h defines functions to open the libraries.The call to
luaopen_io, for instance, creates the
iotable and registers the I/O functions(
io.write, etc.) inside it.
After creating a state and populating it with the standard libraries,it is time to interpret the user input.For each line the user enters,the program first calls
luaL_loadbufferto compile the code.If there are no errors, the call returns zeroand pushes the resulting chunk on the stack.(Remember that we will discuss this 'magic' stack indetail in the next section.)Then the program calls
lua_pcall,which pops the chunk from the stack and runs it in protected mode.Like
lua_pcall returns zero if there are no errors.In case of errors,both functions push an error message on the stack;we get this message with
lua_tostring and,after printing it, we remove it from the stackwith
Notice that, in case of errors,this program simply prints the error message to the standard error stream.Real error handling can be quite complex in Cand how to do it depends on the nature of your application.The Lua core never writes anything directly to any output stream;it signals errors by returning error codes and error messages.Each application can handle these signals in away most appropriate for its needs.To simplify our discussions,we will assume for now a simpleerror handler like the following one,which prints an error message,closes the Lua state, and exits from the whole application:Later we will discuss more about error handling in theapplication code.
Because you can compile Lua both as C and as C++ code,
lua.h does not include this typical adjustment codethat is present in several other C libraries:Therefore, if you have compiled Lua as C code(the most common case)and are using it in C++,you must include
lua.h as follows:A common trick is to create a header file
lua.hppwith the above code and to include this new file in yourC++ programs. Mw2 free mod menu.
|Copyright © 2003–2004 Roberto Ierusalimschy. All rights reserved.|
LUA / C++
C++ Lua Interface Examples
I want to make it like that with the lua api
i have a std:: map like that :
status['equip'] = int;
status['depot'] = int;
status['hold'] = int;
status['slot'] = int;
Now in the c++ this supposed to be a argument in a function in creatureevent, so how to make it the proper way i have it like that
and i get that error in console when the event supposed to be executed