lua-users home
lua-l archive

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


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