Forum

> > CS2D > Scripts > C++ function
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch C++ function

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt C++ function

Gajos
BANNED Off Offline

Zitieren
How I can make, save and use a c++ function in lua script?

C++:
int Add(int x, int y) {
    return x + y;
}

Lua:
print(Add(3,12))

alt Re: C++ function

Starkkz
Moderator Off Offline

Zitieren
Look up on the wiki, there are two tutorials about that from C++ and BlitzMax.

alt Re: C++ function

mafia_man
User Off Offline

Zitieren
user Starkkz hat geschrieben
Look up on the wiki, there are two tutorials about that from C++ and BlitzMax.

Which wiki are you talking about? He didn't say anything about BlitzMax so why pointing him to it?
Just because cs2d is written in BlitzMax it doesn't mean he needs to write and compile the library using BlitzMax and extern C++ in it, he can write the library in C++ and compile it using gcc or g++.

alt Re: C++ function

Starkkz
Moderator Off Offline

Zitieren
user mafia_man hat geschrieben
Which wiki are you talking about? He didn't say anything about BlitzMax so why pointing him to it?
Just because cs2d is written in BlitzMax it doesn't mean he needs to write and compile the library using BlitzMax and extern C++ in it, he can write the library in C++ and compile it using gcc or g++.

Firstly, I meant UnrealSoftware wiki. Secondly, there's no need to be hostile, I haven't responded that way, I just mentioned BlitzMax as an option (Since there's a C++ tutorial and a BlitzMax tutorial).

alt Re: C++ function

Gajos
BANNED Off Offline

Zitieren
user Starkkz hat geschrieben
Look up on the wiki, there are two tutorials about that from C++ and BlitzMax.

Can you send me links to the tutorials?
I must compile this as dll file?

alt Re: C++ function

MikuAuahDark
User Off Offline

Zitieren
1. You even don't need BlitzMax to create LUA modules on CS2D
2. If you write your code on C++, you need to use extern "C" on lua file.

simple lua libraries
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#define LUA_LIB
#define LUA_BUILD_AS_DLL
extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}

int Add(lua_State *L) {
	double x=luaL_checknumber(L,1);
	double y=luaL_checknumber(L,2);
	lua_pushnumber(L,x+y);
	return 1;
}

luaL_reg function_list_that_want_to_exported_to_lua[]={
	{"Add",Add},
};

extern "C" int __declspec(dllexport) luaopen_thelibraryname(lua_State *L) {
	luaL_register(L,"LibraryName",function_list_that_want_to_exported_to_lua);
	return 1;
}
You can find more information on Google
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht