1

Hy!

My problem is simple: I have a function in the extendedgamefunctions class:

In the header:

#include "Gameitems.h" 
extern "C" {
    #include "lua.h"
    #include "lualib.h"
    #include "lauxlib.h"
};

extern std::vector<std::vector<Gameitems>> items;

     class A
        {
             A(); 
             ~A();

        public:
              static void messagewindow(lua_State*);
        };

and the code is:

  Functions extfunctions;
    A::A()
    {}
    A::~A()
    {}

    void A::messagewindow(lua_State *L)
    {
       string message =lua_tostring(L,0);
       extfunctions.Messagewindow(message);
    }

and I want to bind in an another function called Gamefunctions :

#include "Externedgamefunctions.h"

A egfunctions;
lua_State* L;
        void Gamefunctions::luainit()
        {
            L = luaL_newstate();

            /* load Lua base libraries */
            luaL_openlibs(L);
            lua_pushcfunction(L,&A::messagewindow);
            lua_setglobal(L, "messagewindow");
        }

Rather the funtion from another class is static, I get this error:

Error   5   error C2664: 'lua_pushcclosure' : cannot convert parameter 2 from 'void (__cdecl *)(lua_State *)' to 'lua_CFunction'    C:\Users\Bady\Desktop\MY Game\basicconfig\BlueButterfly\BlueButterfly\Gamefunctions.cpp 170

I dont want to make a plus funtion into the gamefunctions to get the messagewindow (unless I have no other coises) because I directly write the extendedgamefunctions to not make an endless stringmonster.

Edit: Almost forgot: Lua 5.2 and c++11

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Bady
  • 56
  • 8

1 Answers1

1

lua_CFunction is defined as typedef int (*lua_CFunction) (lua_State *L);, so you need to change void A::messagewindow(lua_State *L) to int A::messagewindow(lua_State *L).

mtsvetkov
  • 885
  • 10
  • 21
  • Thank you. You are my hero :) – Bady Nov 06 '15 at 14:49
  • It was all in the error message :P Should also be noted that the int you return is the number of values you've pushed to the stack as return values for the function on the lua side. – mtsvetkov Nov 06 '15 at 14:51
  • I figured that out. And yes, that is me. I write an ernomous size of codes, and searching for hours a mispelled "==". But no bigger errors. – Bady Nov 06 '15 at 15:42