English C++ function

7 replies
Goto Page
To the start Previous 1 Next To the start
06.01.14 01:13:11 am
Up
Gajos
BANNED
Offline Off
How I can make, save and use a c++ function in lua script?

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

Lua:
Code:
print(Add(3,12))
Banned for Hacking/Cheating in CS2D /DC
06.01.14 02:45:34 am
Up
Starkkz
Moderator
Offline Off
Look up on the wiki, there are two tutorials about that from C++ and BlitzMax.
lol
06.01.14 03:15:45 am
Up
mafia_man
User
Offline Off
user Starkkz has written:
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++.
06.01.14 03:32:38 am
Up
Starkkz
Moderator
Offline Off
user mafia_man has written:
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).
lol
06.01.14 08:49:22 am
Up
Gajos
BANNED
Offline Off
user Starkkz has written:
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?
Banned for Hacking/Cheating in CS2D /DC
06.01.14 09:14:23 am
Up
DannyDeth
User
Offline Off
@user Gajos: Look at the wiki page that Starkkz posted, it's right there.
06.01.14 01:43:56 pm
Up
MikuAuahDark
User
Offline Off
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
Code:
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
file cs2d LuaJIT for Dedicated Server (13) JIT POWER! | Know your Lua errors! | Part of LÖVE development team since 11.3
To the start Previous 1 Next To the start