65 lines
1.1 KiB
C++
Raw Normal View History

2020-04-28 22:15:43 -07:00
/*
* main.cpp
* Author: Benjamin Sergeant
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
*/
2020-04-20 23:02:23 -07:00
#include <iostream>
extern "C"
{
2020-04-28 22:15:43 -07:00
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
2020-04-20 23:02:23 -07:00
}
#include "functions.hpp"
2020-04-28 18:37:19 -07:00
#include "LuaWebSocket.h"
#include <iostream>
2020-04-20 23:02:23 -07:00
int main()
{
lua_State* L = luaL_newstate();
luaL_openlibs(L);
// Functions
lua_register(L, "info", lua_info);
// Objets
2020-04-28 22:15:43 -07:00
ix::luaopen_WebSocket(L);
2020-04-20 23:02:23 -07:00
2020-04-28 22:15:43 -07:00
//
// Simple version does little error handling
// luaL_dofile(L, "ia.lua");
//
std::string luaFile("ia.lua");
int loadStatus = luaL_loadfile(L, luaFile.c_str());
if (loadStatus)
{
2020-04-28 22:15:43 -07:00
std::cerr << "Error loading " << luaFile << std::endl;
std::cerr << lua_tostring(L, -1) << std::endl;
return 1;
}
else
{
2020-04-28 22:15:43 -07:00
std::cout << "loaded " << luaFile << std::endl;
}
2020-04-28 22:15:43 -07:00
//
// Capture lua errors
//
try
{
lua_call(L, 0, 0);
2020-04-28 22:15:43 -07:00
lua_close(L);
}
2020-04-28 22:15:43 -07:00
catch (const std::runtime_error& ex)
{
lua_close(L);
std::cerr << ex.what() << std::endl;
2020-04-28 22:15:43 -07:00
return 1;
}
2020-04-28 22:15:43 -07:00
return 0;
2020-04-20 23:02:23 -07:00
}