Jump to content

[C++]Sharing libraries, LUA functions


Recommended Posts

  • Bot

GoodDay M2D.

I've compiled successfully a .cpp file using G++ in VirtualBox.

But when i've tried to call one function it return an error.

 

 

src.cpp

#include "./src/lua.h"
#include "./src/stdafx.h"
#include <sstream>
#include "./src/constants.h"
#include "./src/questmanager.h"
#include "./src/questlua.h"
#include "./src/questevent.h"

namespace quest
{
	int _ciao_mondo(lua_State* L)
	{
		ostringstream s;
		combine_lua_string(L, s);
		CQuestManager::Instance().AddScript(s.str());
		return 0;
	}
	
	void RegisterGlobalFunctionTable(lua_State* L)
	{
		extern int quest_setstate(lua_State* L);

		luaL_reg global_functions[] =
		{
			{	"ciao_mondo",_ciao_mondo	},
			{	NULL,	NULL	}
		};
	
		int i = 0;

		while (global_functions[i].name != NULL)
		{
			lua_register(L, global_functions[i].name, global_functions[i].func);
			++i;
		}
	}
} 

quest used to call the function

quest prova begin
 state start begin
  when 9006.chat."LIBRARY TEST" with pc.is_gm() begin
   ciao_mondo("TEST-> ")
  end
 end
end

LUA error

Link -> https://metin2.download/picture/r3F9504x09DVmF8K988YXgTtGTP6KMUj/.gif

 

Code used to load the library:

env LD_32_PRELOAD="/usr/home/game/libs/libfoo.so"

Code used to compile the library:

g++ foo.cpp -o libfoo.so -shared -fPIC

Thx!

Edited by Metin2 Dev
Core X - External 2 Internal

english_banner.gif

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

  • Bronze

 

You are make with original source files?

 

Best Regards

Ellie

Hi Ellie, i'm using this OS and these files-> http://metin2dev.org/board/topic/389-not-really-a-rlsvm-with-freebsd-92-src-compileable/

 

 

I don't sure that file. Because library files creates .cpp and .h(offset address from game).. 

 

Best Regards

Ellie

Do not be sorry, be better.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.