Run block of Lua code inside C ++

2

How do I run a Lua block within a function in C ++?

The idea would look something like:

int main() {
  tipodavariavel script;
  script << "print('Ola mundo')";
  executar(script);
  return 0;
}
    
asked by anonymous 12.02.2015 / 05:53

1 answer

2

This is an example of basic code for executing a Lua Lua. Note that essentially C:

extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

int main() {
    lua_State *L = lua_open();
    luaL_openlibs(L);
    luaL_loadstring(L, "print('Ola mundo')");
    lua_close(L);
    return 0;
}

To compile you should use something like this using GCC / MinGW:

g++ -o interpetadorlua.cpp -llua -ldl

In general this is, I do not know if you need anything specific.

Multiple Library List with examples that can help you integrate in a variety of ways if you want higher level and abstract forms of treat the problem.

    
12.02.2015 / 06:12