bitetti

luasqlite.h

Jan 10th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. /*
  2.  * LuaSQLite.h
  3.  *
  4.  *  Created on: 27/10/2009
  5.  *      Author: bitetti
  6.  */
  7.  
  8. #ifndef LUASQLITE_H_
  9. #define LUASQLITE_H_
  10.  
  11. #include <vector>
  12. #include <string.h>
  13.  
  14. #include <sqlite3.h>
  15.  
  16. #include "SQLiteBase.h"
  17.  
  18. using namespace std;
  19.  
  20. extern "C"{
  21.     #include <lua.h>
  22.     #include <lauxlib.h>
  23.     #include <lualib.h>
  24. }
  25.  
  26. class LuaSQLite : public SQLiteBase {
  27.  
  28.     #define LUASQLITE_CLASSNAME "SQLite"
  29.  
  30.     public:
  31.         /*
  32.          * Construtor
  33.          */
  34.         LuaSQLite();
  35.     public:
  36.         /*
  37.          * Destrutor
  38.          */
  39.         virtual ~LuaSQLite();
  40.  
  41.     public:
  42.         /*
  43.          * create instance - Gera uma nova instância de controle retornando seu ponteiro
  44.          */
  45.         static LuaSQLite* create( lua_State * );
  46.         static LuaSQLite* create( lua_State *, const char* );
  47.  
  48.         /*
  49.          * Encerra todas as instancias aertas
  50.          */
  51.         static void dispose();
  52.  
  53.         /*
  54.          * Registra funções no State principal de Lua
  55.          */
  56.         static void registraFuncoes( lua_State * );
  57.  
  58.     //membros
  59.     private:
  60.         lua_State* Lua;
  61.  
  62.         static vector<LuaSQLite*> elements;
  63.  
  64.     public:
  65.         /**
  66.          * Lua Binding function to check
  67.          */
  68.         static LuaSQLite* checkClass (lua_State *, int);
  69.         static void* getObject (lua_State *, int);
  70.  
  71.     //metodos
  72.     public:
  73.         /**
  74.          * Adiciona lua_State ao sistema
  75.          */
  76.         void addLuaState( lua_State*);
  77.  
  78.         /**
  79.          * carrega cenario e inicializa db
  80.          */
  81.         static int run(lua_State*, const char*);
  82.  
  83.     /**
  84.      * Registros para Lua
  85.      */
  86.     static const luaL_reg meta_methods[];
  87.     static const luaL_reg class_methods[];
  88.     #define newtable(L) (lua_newtable(L), lua_gettop(L))
  89.  
  90.  
  91.  
  92.     /**
  93.      * Biblioteca de funções para Lua/SQLite
  94.      */
  95.         static int open_database(lua_State*);
  96.         static int close_database(lua_State*);
  97.  
  98.         static int query(lua_State*);
  99.         static int fetchRow(lua_State*);
  100.         static int sql_error(lua_State*);
  101.         static int reset_stmt(lua_State*);
  102.         static int getMainDatabase(lua_State*);
  103.  
  104. };
  105.  
  106. #endif /* LUASQLITE_H_ */
Advertisement
Add Comment
Please, Sign In to add comment