lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


You must declare your function 
__declspec(dllexport) int my_c_function(lua_State* L)
{
...
}

or use  .def file in project.

Regards
Alexander Altshuler

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Lloyd
Sent: Thursday, May 14, 2009 6:38 PM
To: Lua list
Subject: Re: Will Lua work in this situation?

On Thu, 14 May 2009 18:15:43 +0530, Jerome Vuarand  
<jerome.vuarand@gmail.com> wrote:

> You can use either package.loadlib or require.
> With loadlib, you would just have to put your lua_CFunction into a
> shared library, then get it from Lua and call it. For example in foo.c
> you would put:
> int my_c_function(lua_State* L)
> {
>   const char* name = luaL_checkstring(L, 1);
>   printf("Hello %s!\n", name);
>   return 0;
> }
> and in Lua you would write:
> local my_c_function = assert(package.loadlib("foo.so",
"my_c_function"))
> my_c_function("bob")


I am trying this method, but it is not working, I am making mistake  
someware :( I am working on Windows, staretd a dll project (Visual
Studio  
2005), and written as given below

int my_c_function(lua_State* L)
{
   const char* name = luaL_checkstring(L, 1);
   printf("Hello %s!\n", name);
   return 0;
}

only "dll" file is generated (no lib file), then when I try to call

local my_c_function = assert(package.loadlib("mylib.dll",
"my_c_function"))

 from my Lua interpreter I get this error

stdin:1: The specified procedure could not be found.

stack traceback:
         [C]: in function 'assert'
         stdin:1: in main chunk
         [C]: ?

I again tried with changing the "my_c_function" like this

int __declspec(dllexport) my_c_function(lua_State* L)
{
   const char* name = luaL_checkstring(L, 1);
   printf("Hello %s!\n", name);
   return 0;
}

Again I am getting the same error message. Where am I making mistake?

Thanks for your help,
  Lloyd

______________________________________
Scanned and protected by Email scanner
No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.329 / Virus Database: 270.12.21/2103 - Release Date:
05/13/09 18:04:00