Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "lua5.2/lua.h"
- #include "lua5.2/lualib.h"
- #include "lua5.2/lauxlib.h"
- // Error handling
- void bail(lua_State*, const char*);
- int main() {
- // Init Lua
- lua_State* Lua = luaL_newstate();
- // Call Lua base library
- luaopen_base(Lua);
- // Call Lua auxiliary library
- luaL_openlibs(Lua);
- // Main block
- int state =
- luaL_dostring(Lua,
- "Vector = require \"Vector\";"
- "v = Vector:from_table({1, 2, 3, 4});"
- "v = v + 1;"
- "assert(#v == 4);"
- "assert(v[1] == 2);");
- if (state != LUA_OK) {
- bail(Lua, "failed to load Lua statement");
- }
- lua_close(Lua);
- return 0;
- }
- void bail(lua_State* L, const char* msg) {
- fprintf(stderr, "ERROR: %s: %s\n",
- msg, lua_tostring(L, -1));
- lua_close(L);
- exit(EXIT_FAILURE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement