rendered paste body#include "lua.hpp"#include <iostream>using namespace std;class lua{ private: lua_State* L; public: lua() { L = lua_open(); luaL_openlibs(L); }; lua(lua_State* P) { L = P; }; ~lua() { lua_close(L); }; void dofile(const char* fn); void dostring(const char* str); //stack queriers const char* getstring(int idx); double getnumber(int idx); //stack pushers void pushnumber(double i); void pushstring(const char* str); void pushcfunction(int (lua_State*)); void register_func(const char* name, int ptr(lua_State*)); void push(const char*); void push(double i); void push(int ptr(lua_State*)); //pushcfunc //stack check bool isbool(int); bool isnumber(int); bool isstring(int); //stack etc. void pop(int i); //debug const char* getError();};using namespace std;void lua::dofile(const char* fn){ cout<<"Opening: "<<fn<<endl; if (luaL_dofile(L,fn)) cout<<"Error: ("<<this->getError()<<")"<<endl;}void lua::dostring(const char* str){ if (luaL_loadstring(L,str) != 0 ) { cout<<"Error: ("<<this->getError()<<") in string: ("<<str<<")"<<std::endl; }else{ if (lua_pcall(L,0,0,0) != 0 ) { cout<<"Error: ("<<this->getError()<<") while running string: ("<<str<<")"<<std::endl; } } }const char* lua::getError(){ const char* err = ""; //this->stackDump(); err = lua_tostring(L,-1); lua_pop(L,1); return err;}double lua::getnumber(int idx){ return lua_tonumber(L,idx);}const char* lua::getstring(int idx){ return lua_tostring(L,idx);}void lua::pushstring(const char* str){ lua_pushstring(L,str);}void lua::pushnumber(double i){ lua_pushnumber(L,i);}void lua::pushcfunction(int ptr(lua_State*)){ lua_pushcfunction(L,ptr); }void lua::register_func(const char* name, int ptr(lua_State*)){ lua_register(L,name,ptr);} void lua::pop(int i){ lua_pop(L,i);}bool lua::isnumber(int idx){ if (lua_isnumber(L,idx) == 1) {return true;}else{return false;}}bool lua::isstring(int idx){ if (lua_isstring(L,idx) == 1) {return true;}else{return false;}}bool lua::isbool(int idx){ if (lua_isboolean(L,idx) == 1) {return true;}else{return false;}}//bootleg'd thing.void lua::push(const char* str) //string{ this->pushstring(str);}void lua::push(double i) //number{ this->pushnumber(i);}void lua::push(int ptr(lua_State*)){ this->pushcfunction(ptr);}