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

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. You are my hero :)
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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.