• Subject: Re: Problem calling c++ from Lua (MS-Windows version)
• From: jseb <gmane2010@...>
• Date: Mon, 21 Feb 2011 17:37:36 +0100

I did a try with Visual C++ (express edition, the one you get for free on microsoft website)
```
Here is my compilation on command line:

set incpath=%vcinstalldir%\include
set libpath=%vcinstalldir%\lib
cl foo.cpp -c /I%incpath%\lua

And i get "foo.dll", of course.
When i try require "foo" in lua, i still get :

> require "foo"
La procÚdure spécifiée est introuvable.

(same as my previous try with g++)

Here is the source-file.
```
Are there any windows user who could help me, and explain how to compile it, whatever toolchain you use (Visual C, mingw ...).
```Thank you!

```
I rewrite the source file, now it's very simple. It still works without problems in Linux.
```

extern "C" {
#include <stdio.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

static int lua_print(lua_State*);
__declspec(dllexport)
int luaopen_libfoo(lua_State*);
}

static int lua_print(lua_State *L)
{
printf ("called: lua_print\n");
return 0;
}

static const struct luaL_Reg foo_fx [] = {
{ "print", lua_print },
{ NULL, NULL } //dernier element obligatoire
};

__declspec(dllexport)
int luaopen_libfoo(lua_State *L)
{
luaL_register (L, "foo", foo_fx);
return 1;
}

```

• Follow-Ups:
• References: