Some problems while using C++ with lua

Posted by Doghell on Tue 08 Sep 2009 03:03 AM — 2 posts, 11,716 views.

#0
hey,everybody:
when i using C++ with lua,I have some problems which I cannot work through.
see I want to write a program to open a file and using lua to deal the strings in the file,and then write to another file
so i try to register the deal function to the lua ,but I don't want to register all of the class to lua.
I will use some code to describe my problems:
I just want it like this:

class A
{
public:
    int read (FILE fd,string m_string);
    int deal(Lua_state *L); // this function will deal with   m_string by some parameters in the lua file
    int write(string m_string1,FILE fd1)
private:
    string m_string;
    string m_string1;
};

I'd like to use the read and write function in my main function and the deal in the lua file , but I don't know how to do.
thank regards
Australia Forum Administrator #1
That isn't exactly code, it is a data declaration. Nor does this post seem to have much to do with MUSHclient.

Try looking at this post:

Template:post=6400
Please see the forum thread: http://gammon.com.au/forum/?id=6400.


Also, the Lua mailing list is quite helpful:

lua@bazar2.conectiva.com.br

Basically I think you want to take your string, convert it into const char * (in the case of the string class that is m_string.c_str () ), and then push that onto the Lua stack, then call your routine, then get the results off the stack. My post above shows the general idea.