Added VS2013 files to gitignore.

This commit is contained in:
ThePhD 2013-12-01 17:27:17 -05:00
parent 1f22cdd19e
commit 24c76d3e03
2 changed files with 202 additions and 192 deletions

24
.gitignore vendored
View File

@ -1,7 +1,17 @@
obj/* obj/*
bin/* bin/*
*.ninja* *.ninja*
demacro.txt demacro.txt
Shinobi2 Shinobi2
dev.* dev.*
main.cpp main.cpp
lua-5.2.2/
Debug/
Release/
x64/
*.vcxproj
*.vcxproj.filters
*.tlog
*.lastbuildstate
*.idb
*.sln

View File

@ -1,186 +1,186 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013 Danny Y., Rapptz // Copyright (c) 2013 Danny Y., Rapptz
// Permission is hereby granted, free of charge, to any person obtaining a copy of // Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in // this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to // the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so, // the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions: // subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SOL_STATE_HPP #ifndef SOL_STATE_HPP
#define SOL_STATE_HPP #define SOL_STATE_HPP
#include "error.hpp" #include "error.hpp"
#include "table.hpp" #include "table.hpp"
#include <memory> #include <memory>
namespace sol { namespace sol {
namespace detail { namespace detail {
template<class T, class...> template<class T, class...>
struct are_same : std::true_type {}; struct are_same : std::true_type {};
template<class T, class U, class... Args> template<class T, class U, class... Args>
struct are_same<T, U, Args...> : std::integral_constant<bool, std::is_same<T,U>{} && are_same<T, Args...>{}> {}; struct are_same<T, U, Args...> : std::integral_constant<bool, std::is_same<T,U>::value && are_same<T, Args...>::value> {};
int atpanic(lua_State* L) { int atpanic(lua_State* L) {
throw sol_error(lua_tostring(L, -1)); throw sol_error(lua_tostring(L, -1));
} }
} // detail } // detail
enum class lib : char { enum class lib : char {
base, base,
package, package,
coroutine, coroutine,
string, string,
os, os,
math, math,
table, table,
debug, debug,
bit32, bit32,
io, io,
count count
}; };
class state { class state {
private: private:
std::unique_ptr<lua_State, void(*)(lua_State*)> L; std::unique_ptr<lua_State, void(*)(lua_State*)> L;
table reg; table reg;
table global; table global;
public: public:
state(): state():
L(luaL_newstate(), lua_close), L(luaL_newstate(), lua_close),
reg(L.get(), LUA_REGISTRYINDEX), reg(L.get(), LUA_REGISTRYINDEX),
global(reg.get<table>(LUA_RIDX_GLOBALS)) { global(reg.get<table>(LUA_RIDX_GLOBALS)) {
lua_atpanic(L.get(), detail::atpanic); lua_atpanic(L.get(), detail::atpanic);
} }
state(const std::string& filename): state(const std::string& filename):
L(luaL_newstate(), lua_close), L(luaL_newstate(), lua_close),
reg(L.get(), LUA_REGISTRYINDEX), reg(L.get(), LUA_REGISTRYINDEX),
global(reg.get<table>(LUA_RIDX_GLOBALS)) { global(reg.get<table>(LUA_RIDX_GLOBALS)) {
lua_atpanic(L.get(), detail::atpanic); lua_atpanic(L.get(), detail::atpanic);
open_file(filename); open_file(filename);
} }
template<typename... Args> template<typename... Args>
void open_libraries(Args&&... args) { void open_libraries(Args&&... args) {
static_assert(detail::are_same<lib, Args...>{}, "all types must be libraries"); static_assert(detail::are_same<lib, Args...>{}, "all types must be libraries");
if(sizeof...(args) == 0) { if(sizeof...(args) == 0) {
luaL_openlibs(L.get()); luaL_openlibs(L.get());
return; return;
} }
lib libraries[1 + sizeof...(args)] = { lib::count, std::forward<Args>(args)... }; lib libraries[1 + sizeof...(args)] = { lib::count, std::forward<Args>(args)... };
for(auto&& library : libraries) { for(auto&& library : libraries) {
switch(library) { switch(library) {
case lib::base: case lib::base:
luaL_requiref(L.get(), "base", luaopen_base, 1); luaL_requiref(L.get(), "base", luaopen_base, 1);
break; break;
case lib::package: case lib::package:
luaL_requiref(L.get(), "package", luaopen_package, 1); luaL_requiref(L.get(), "package", luaopen_package, 1);
break; break;
case lib::coroutine: case lib::coroutine:
luaL_requiref(L.get(), "coroutine", luaopen_coroutine, 1); luaL_requiref(L.get(), "coroutine", luaopen_coroutine, 1);
break; break;
case lib::string: case lib::string:
luaL_requiref(L.get(), "string", luaopen_string, 1); luaL_requiref(L.get(), "string", luaopen_string, 1);
break; break;
case lib::table: case lib::table:
luaL_requiref(L.get(), "table", luaopen_table, 1); luaL_requiref(L.get(), "table", luaopen_table, 1);
break; break;
case lib::math: case lib::math:
luaL_requiref(L.get(), "math", luaopen_math, 1); luaL_requiref(L.get(), "math", luaopen_math, 1);
break; break;
case lib::bit32: case lib::bit32:
luaL_requiref(L.get(), "bit32", luaopen_bit32, 1); luaL_requiref(L.get(), "bit32", luaopen_bit32, 1);
break; break;
case lib::io: case lib::io:
luaL_requiref(L.get(), "io", luaopen_io, 1); luaL_requiref(L.get(), "io", luaopen_io, 1);
break; break;
case lib::os: case lib::os:
luaL_requiref(L.get(), "os", luaopen_os, 1); luaL_requiref(L.get(), "os", luaopen_os, 1);
break; break;
case lib::debug: case lib::debug:
luaL_requiref(L.get(), "debug", luaopen_debug, 1); luaL_requiref(L.get(), "debug", luaopen_debug, 1);
break; break;
case lib::count: case lib::count:
break; break;
} }
} }
} }
void script(const std::string& code) { void script(const std::string& code) {
if(luaL_dostring(L.get(), code.c_str())) { if(luaL_dostring(L.get(), code.c_str())) {
lua_error(L.get()); lua_error(L.get());
} }
} }
void open_file(const std::string& filename) { void open_file(const std::string& filename) {
if(luaL_dofile(L.get(), filename.c_str())) { if(luaL_dofile(L.get(), filename.c_str())) {
lua_error(L.get()); lua_error(L.get());
} }
} }
template<typename T, typename U> template<typename T, typename U>
T get(U&& key) const { T get(U&& key) const {
return global.get<T>(std::forward<U>(key)); return global.get<T>(std::forward<U>(key));
} }
template<typename T, typename U> template<typename T, typename U>
state& set(T&& key, U&& value) { state& set(T&& key, U&& value) {
global.set(std::forward<T>(key), std::forward<U>(value)); global.set(std::forward<T>(key), std::forward<U>(value));
return *this; return *this;
} }
template<typename T> template<typename T>
table create_table(T&& key, int narr = 0, int nrec = 0) { table create_table(T&& key, int narr = 0, int nrec = 0) {
if(narr == 0 && nrec == 0) { if(narr == 0 && nrec == 0) {
lua_newtable(L.get()); lua_newtable(L.get());
} }
else { else {
lua_createtable(L.get(), narr, nrec); lua_createtable(L.get(), narr, nrec);
} }
table result(L.get()); table result(L.get());
lua_pop(L.get(), 1); lua_pop(L.get(), 1);
global.set(std::forward<T>(key), result); global.set(std::forward<T>(key), result);
return result; return result;
} }
table create_table(int narr = 0, int nrec = 0) { table create_table(int narr = 0, int nrec = 0) {
if(narr == 0 && nrec == 0) { if(narr == 0 && nrec == 0) {
lua_newtable(L.get()); lua_newtable(L.get());
} }
else { else {
lua_createtable(L.get(), narr, nrec); lua_createtable(L.get(), narr, nrec);
} }
table result(L.get()); table result(L.get());
lua_pop(L.get(), 1); lua_pop(L.get(), 1);
return result; return result;
} }
table global_table() const { table global_table() const {
return global; return global;
} }
table registry() const { table registry() const {
return reg; return reg;
} }
}; };
} // sol } // sol
#endif // SOL_STATE_HPP #endif // SOL_STATE_HPP