/* * Baltisot * Copyright (C) 1999-2003 Nicolas "Pixel" Noble * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* $Id: BLua.h,v 1.6 2003-12-06 04:26:16 pixel Exp $ */ #ifndef __BLUA_H__ #define __BLUA_H__ #include #include #include #include class Lua : public Base { public: Lua(); Lua(const Lua &) throw (GeneralException); virtual ~Lua(); void open_base(); void open_table(); void open_io(); void open_string(); void open_math(); void open_debug(); void declarefunc(const String &, lua_CFunction, int = LUA_GLOBALSINDEX); void call(const String &, int = LUA_GLOBALSINDEX, int = 0, int = 0); void call(int = 0, int = 0); void push(); void push(lua_Number); void push(const String &); void push(bool); void push(void *); void push(lua_CFunction, int = 0); void pop(int = 1); void newtable(); void settable(int = -3, bool raw = false); void gettable(int = -2, bool raw = false); int gettop(); void error(const String &); int type(int = -1); bool isnil(int = -1); bool isboolean(int = -1); bool isnumber(int = -1); bool isstring(int = -1); bool istable(int = -1); bool isfunction(int = -1); bool iscfunction(int = -1); bool isuserdata(int = -1); bool islightuserdata(int = -1); bool toboolean(int = -1); lua_Number tonumber(int = -1); String tostring(int = -1); lua_CFunction tocfunction(int = -1); void * touserdata(int = -1); Lua * tothread(int = -1); void load(Handle *, bool docall = true) throw (GeneralException); void dump(Handle *, bool strip = true); Lua * thread(); static Lua * find(lua_State *) throw (GeneralException); void showerror(); int getmetatable(int = -1); int setmetatable(int = -2); private: Lua(lua_State *); lua_State * L; static std::map lualist; }; class LuaObject : public Base { public: LuaObject() : wantdestruct(false), pushed(false) {} virtual void push(Lua *) throw (GeneralException); static void * getme(Lua *, int = 1) throw (GeneralException); void pushdestruct(Lua *) throw (GeneralException); protected: virtual void pushmembers(Lua *) = 0; void pushme(Lua *, void *); static void pushit(Lua *, const String &, lua_CFunction); bool wantdestruct, pushed; }; #endif