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"
|
2020-04-28 19:11:06 -07:00
|
|
|
#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
|
2020-04-28 22:22:45 -07:00
|
|
|
// luaL_dofile(L, "echo_client.lua");
|
2020-04-28 22:15:43 -07:00
|
|
|
//
|
2020-04-28 22:22:45 -07:00
|
|
|
std::string luaFile("echo_client.lua");
|
2020-04-28 22:15:43 -07:00
|
|
|
int loadStatus = luaL_loadfile(L, luaFile.c_str());
|
2020-04-28 19:11:06 -07:00
|
|
|
if (loadStatus)
|
|
|
|
{
|
2020-04-28 22:15:43 -07:00
|
|
|
std::cerr << "Error loading " << luaFile << std::endl;
|
2020-04-28 19:11:06 -07:00
|
|
|
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 19:11:06 -07:00
|
|
|
}
|
|
|
|
|
2020-04-28 22:15:43 -07:00
|
|
|
//
|
|
|
|
// Capture lua errors
|
|
|
|
//
|
|
|
|
try
|
|
|
|
{
|
2020-04-28 19:11:06 -07:00
|
|
|
lua_call(L, 0, 0);
|
2020-04-28 22:15:43 -07:00
|
|
|
lua_close(L);
|
2020-04-28 19:11:06 -07:00
|
|
|
}
|
2020-04-28 22:15:43 -07:00
|
|
|
catch (const std::runtime_error& ex)
|
|
|
|
{
|
|
|
|
lua_close(L);
|
2020-04-28 19:11:06 -07:00
|
|
|
std::cerr << ex.what() << std::endl;
|
2020-04-28 22:15:43 -07:00
|
|
|
return 1;
|
2020-04-28 19:11:06 -07:00
|
|
|
}
|
2020-04-28 22:15:43 -07:00
|
|
|
|
|
|
|
return 0;
|
2020-04-20 23:02:23 -07:00
|
|
|
}
|