Jump to content
  • Advertisement

chophias

Member
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

100 Neutral

About chophias

  • Rank
    Newbie
  1. Hello, I 've got the following code extern "C" { #include "lua/lua.h" #include "lua/lauxlib.h" } #include "luabind/luabind.hpp" #include <iostream> using namespace std; void teller() { int i = 0; for(i=0;i<10;i++) { cout << i << ","; } } int main() { //create a lua state lua_State* pLua = lua_open(); //open luabind luabind::open(pLua); /* Register functions and classes with luabind here */ luabind::module(pLua) [ luabind::def("teller", &teller) ]; /* load and run the script here */ luaL_dofile(pLua, "script1.lua"); //luaL_dostring(pLua, "teller()"); //tidy up lua_close(pLua); return 0; } script1.lua print("[lua]: About to call the C++ teller() function") teller() If I uncomment //luaL_dostring(pLua, "teller()"); , then i get the output from the teller() function in my console window, If I use luaL_dofile(pLua, "script1.lua"); , then i dont get anything in my console window, just "process returned 0, 0x0) Im using lua 5.1.4 & luabind 0.9.1 Anyone can tell me how to grab the output from a .lua file that was executed from inside c++?
  2. chophias

    Cannot rename function

    1. Checked 2. Checked 3. Checked 4. Not using precompiled headers 5. ok i'm checking this last possibility but i never had problems, using default Codeblocks setup mingw32
  3. Hello, I'm using an class to load and draw images using SDL. There's one thing I dont understand. I cannot rename the LoadImage functions. If for instance i try to rename "static SDL_Surface* LoadImage(const string& file)" int "static SDL_Surface* LoadImagefile(const string& file)" i get the folowing errors: Graphics.cpp|9|error: no 'SDL_Surface* Graphics::LoadImagefile(const std::string&)' member function declared in class 'Graphics'| Graphics.cpp|36|error: no 'SDL_Surface* Graphics::LoadImagefile(const std::string&, Color&)' member function declared in class 'Graphics'| I just dont get it why i'm getting these errors, I just rename "LoadImage" to "LoadImagefile" in header and source file but when compiling i get these errors. I'm sure there's a logical answer. #ifndef GRAPHICS_H_INCLUDED #define GRAPHICS_H_INCLUDED #include "SDL.h" #include "SDL_image.h" #include <string> using namespace std; class Color; class Graphics { public: Graphics(); static SDL_Surface* LoadImage(const string& file); static SDL_Surface* LoadImage(const string& file, Color& transparent); static bool DrawImage(SDL_Surface* source, float x, float y); static bool DrawImage(SDL_Surface* source, float x, float y, int sx, int sy, int w, int h); // Draws only part of the source image static void DrawHorizontalLine(int x1, int x2, int y, int thickness, Color& color); static void DrawVerticalLine(int y1, int y2, int x, int thickness, Color& color); static bool SetTransparencyColor(SDL_Surface* source, Color& color); static void SetTransparency(SDL_Surface* source, float alpha); }; #endif // GRAPHICS_H_INCLUDED #include "Graphics.h" #include "Color.h" #include "Screen.h" Graphics::Graphics() {} //============================================================================================================================ SDL_Surface* Graphics::LoadImage(const string& file) { SDL_Surface* Surf_Temp = NULL; SDL_Surface* Surf_Return = NULL; if((Surf_Temp = IMG_Load(file.c_str())) == NULL) { if(file.empty()) { printf("Unable to load image: Empty string passed!\n"); } else { printf("Unable to load image: %s\n", file.c_str()); } return NULL; } Surf_Return = SDL_DisplayFormat(Surf_Temp); SDL_FreeSurface(Surf_Temp); return Surf_Return; } //============================================================================================================================ SDL_Surface* Graphics::LoadImage(const std::string& file, Color& transparent) { SDL_Surface* Surf_Temp = NULL; SDL_Surface* Surf_Return = NULL; if((Surf_Temp = IMG_Load(file.c_str())) == NULL) { if(file.empty()) { printf("Unable to load image: Empty string passed!\n"); } else { printf("Unable to load image: %s\n", file.c_str()); } return NULL; } Surf_Return = SDL_DisplayFormat(Surf_Temp); SDL_FreeSurface(Surf_Temp); Graphics::SetTransparencyColor(Surf_Return, transparent); return Surf_Return; } //============================================================================================================================ bool Graphics::DrawImage(SDL_Surface* source, float x, float y) { if(!source) {return false;} bool locked = false; SDL_Rect DestRect; DestRect.x = (Sint16)x; DestRect.y = (Sint16)y; if(SDL_MUSTLOCK(source)) { SDL_LockSurface(source); locked = true; } SDL_BlitSurface(source, NULL, Screen::GetScreen().GetScreenSurface(), &DestRect); if(locked) { SDL_UnlockSurface(source); } return true; } //============================================================================================================================ bool Graphics::DrawImage(SDL_Surface* source, float x, float y, int sx, int sy, int w, int h) { if(source == NULL) {return false;} SDL_Rect DestRect; DestRect.x = (Sint16)x; DestRect.y = (Sint16)y; SDL_Rect SourceRect; SourceRect.x = sx; SourceRect.y = sy; SourceRect.w = w; SourceRect.h = h; SDL_BlitSurface(source, &SourceRect, Screen::GetScreen().GetScreenSurface(), &DestRect); return true; } //============================================================================================================================ bool Graphics::SetTransparencyColor(SDL_Surface* source, Color& color) { if(source == NULL) {return false;} SDL_SetColorKey(source, SDL_SRCCOLORKEY, SDL_MapRGB(source->format, color.GetR(), color.GetG(), color.GetB())); return true; } //============================================================================================================================ void Graphics::SetTransparency(SDL_Surface* source, float alpha) { if(!source || (alpha < 0.f || alpha > 1.f)) return; if(SDL_SetAlpha(source, SDL_SRCALPHA, (int)((1-alpha) * 255)) == -1) {return;} } //============================================================================================================================ void Graphics::DrawHorizontalLine(int x1, int x2, int y, int thickness, Color& color) { SDL_Rect DestRect; DestRect.x = x1; DestRect.y = y; DestRect.h = thickness; DestRect.w = x2 - x1; SDL_FillRect(Screen::GetScreen().GetScreenSurface(), &DestRect, SDL_MapRGB(Screen::GetScreen().GetScreenSurface()->format, color.GetR(), color.GetG(), color.GetB())); } //========================================================================================================================= void Graphics::DrawVerticalLine(int y1, int y2, int x, int thickness, Color& color) { SDL_Rect DestRect; DestRect.x = x; DestRect.y = y1; DestRect.h = y2 - y1; DestRect.w = thickness; SDL_FillRect(Screen::GetScreen().GetScreenSurface(), &DestRect, SDL_MapRGB(Screen::GetScreen().GetScreenSurface()->format, color.GetR(), color.GetG(), color.GetB())); } //=========================================================================================================================
  4. chophias

    SDL sprite clipping problem

    You're right, its not related at all, but it was only something to show what i wanted to ask Big thanks for your patience.
  5. chophias

    SDL sprite clipping problem

    call me stupid but i just can't figure it out: To make it simple for myself i made the following model, i made 4 files. In cars::carmax() i have "return loco.trainmax()", when i compile i get : `loco' undeclared (first use this function) Can you modify my code with your reference methode so loco.trainmax() would be known inside cars::carmax() That would really help me alot to learn to understand that stuff . cars.h class cars { public: cars(); int maxpassengerscar; int carmax(); }; cars.cpp #include "trains.h" #include "cars.h" #include <iostream> using namespace std; cars::cars() { maxpassengerscar = 5; } int cars::carmax() { return loco.trainmax() } int main() { cars fiat; trains loco; cout << loco.trainmax(); // should cout 150 return 0; } trains.h class trains { public: trains(); int maxpassengers; int trainmax(); }; trains.cpp #include "trains.h" trains::trains() { maxpassengers = 150; } int trains::trainmax() { return maxpassengers; }
  6. chophias

    SDL sprite clipping problem

    Ok, so in fact what happens is that a copy of "one" is created, that copy got the same values as the existing (primary)version of "one", and what you mean is that if i change any value i will not change the value of the primary instance of "one". Ok so as long as you dont need to change anything, that's not really a problem. A better solution is to pass a reference to the constructor of the class, can you give me a simple example how i can do that
  7. chophias

    SDL sprite clipping problem

    Well, what i tried now : i redeclared "one": triangle one; in CApp_OnRender.cpp and guess what, it worked. Is this the way i should proceed, just redeclare an instance where you want to use it? thats if you're using it outside its own class
  8. chophias

    SDL sprite clipping problem

    I do use .h and .cpp files. I think maybe the problem is related to bad "includes" for example, i got a " one undeclared" error when compiling this: CApp_OnRender.cpp #include "CApp.h" void CApp::OnRender() { double grades; grades = one.obtuse_angle(); // one is an instance of triangle class } So actually my problem is that i dont know how to access an instance of an object from inside another class. The function obtuse_angle(); is a public function inside the triangle class so that should be accessible. The triangle class instance "one" is not known inside CApp_OnRender.cpp, Even if i add (#include "triangle.h") i still receive the same error when compiling: CApp_OnRender.cpp: `one' undeclared (first use this function) I also tried to add (#include "triangle.h") to CApp.h, same error when compiling I can also say that the object instance "one" is created before i get inside CApp::OnRender() This is the code from CApp.h //============================================================================== // SDL Tutorial 1 //============================================================================== #ifndef _CAPP_H_ #define _CAPP_H_ #include <SDL/SDL.h> #include "SDL/SDL_gfxPrimitives.h" #include "CEvent.h" #include "CSurface.h" #include "SDL/SDL_ttf.h" //============================================================================== class CApp : public CEvent { private: bool Running; SDL_Surface* Surf_Display; SDL_Surface* Surf_Test; SDL_Surface* Surf_Message; //SDL_Surface* Surf_Message2; TTF_Font* font ; public: CApp(); int OnExecute(); public: bool OnInit(); void OnEvent(SDL_Event* Event); void OnExit(); void OnLoop(); void OnRender(); void OnCleanup(); }; //============================================================================== #endif
  9. Hello, What i did is the following: I took the code to create a button from Lazy Foo's Lesson 9 Mouse Events. I then used that buttonclass in another tutorial project from SDLTutorials(tictactoe). I tried to integrate the buttonclass in that project, but got some problems in doing so. it's driving me nuts basicly when i try to compile what i got so far i receive : "\SDLTutorialBasics\CApp_OnRender.cpp `resetButton' undeclared (first use this function) " <=from Dev-C resetButton is an instance of the buttonclass, this is the function where i use resetButton, its in CApp_OnRender.cpp : CSurface::OnDraw(Surf_Display, Surf_Button, 690, 455, &resetButton.a_rect_clips[ 1 ]); Now what i dont understand is why i get this undeclared error, i made everything public in my button class, just to test. If i use "CSurface::OnDraw(Surf_Display, Surf_Button, 690, 455,0,0,120 ,90);" to render the button sprite then its ok Forgive me if the answer is something very simple, i'm an absolute beginner in c++. I attached my project, think that will help
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!