testapp.cpp 563 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

int main()
{
    lua_State* L = luaL_newstate();

    // load the libs
    luaL_openlibs(L);

14
15
16
17
18
19
20
21
22
23
24
    // run a Lua script here; true is returned if there were errors
    if (luaL_dofile(L, "script.lua")) {
        const char* msg = lua_tostring(L, -1);

        if (msg == nullptr)
            printf("(error object is not a string)");
        else
            printf("%s", msg);

        lua_pop(L, 1);
    }
25
26
27
28
29
30
31

    printf("\nI am done with Lua in C++.\n");

    lua_close(L);

    return 0;
}