示例#1
0
int initialize(lua_State* state)
{
	Database* mysqldb = makeDatabase(state);

	if (!mysqldb) return 0;

	std::string error;
	if (!mysqldb->Initialize(error))
	{
		LUA->PushBool(false);
		LUA->PushString(error.c_str());
		delete mysqldb;
		return 2;
	}

	UserData* userdata = (UserData*)LUA->NewUserdata(sizeof(UserData));
	userdata->data = mysqldb;
	userdata->type = DATABASE_ID;

	int uData = LUA->ReferenceCreate();

	LUA->ReferencePush(iRefDatabases);
	LUA->PushNumber(mysqldb->GetTableIndex());
	LUA->ReferencePush(uData);
	LUA->SetTable(-3);

	LUA->ReferencePush(uData);
	LUA->ReferenceFree(uData);
	LUA->CreateMetaTableType(DATABASE_NAME, DATABASE_ID);
	LUA->SetMetaTable(-2);
	return 1;
}
示例#2
0
int DBDisconnect(lua_State* state)
{
	LUA->CheckType(1, DATABASE_ID);

	Database * mysqldb = *reinterpret_cast<Database **>(LUA->GetUserdata(1));

	if (!mysqldb) {
		LUA->ThrowError("Attempted to call Disconnect on a shutdown database");
		return 0;
	}

	LUA->ReferencePush(iRefDatabases);
	LUA->PushNumber(mysqldb->GetTableIndex());
	LUA->PushNil();
	LUA->SetTable(-3);

	DisconnectDB(state, mysqldb);

	return 0;
}
示例#3
0
int create(lua_State* state)
{
	Database* mysqldb = makeDatabase(state);

	if (!mysqldb) return 0;

	UserData* userdata = (UserData*)LUA->NewUserdata(sizeof(UserData));
	userdata->data = mysqldb;
	userdata->type = DATABASE_ID;

	int uData = LUA->ReferenceCreate();

	LUA->ReferencePush(iRefDatabases);
	LUA->PushNumber(mysqldb->GetTableIndex());
	LUA->ReferencePush(uData);
	LUA->SetTable(-3);

	LUA->ReferencePush(uData);
	LUA->ReferenceFree(uData);
	LUA->CreateMetaTableType(DATABASE_NAME, DATABASE_ID);
	LUA->SetMetaTable(-2);
	return 1;
}