s-ol wrote:
no, it should be working like that.
If it's not the Lua Version, it's probably an 32/64bit problem. Your lua.h and lua5.1.lib are probably 32 bit if they are in Program Files x86, and I suppose your love.exe is in "regular" Program Files and x64? you need to make sure they are either both x32 or both x64.
My lua is 32-bit. And I checked LOVE in the task manager and found that my love.exe is also 32-bit. Actually, I only downloaded the 32-bit version of LOVE.
And if I rename the dll, LOVE reports that "Error: error loading module 'TestDll2' from file '.\TestDll2.dll':"
So it is consistent with the dll?
TestDll.cpp
Code: Select all
#include <cstdio>
#include "TestDll.h"
static int averageFunc(lua_State *L)
{
int n = lua_gettop(L);
double sum = 0;
int i;
for (i = 1; i <= n; i++)
sum += lua_tonumber(L, i);
lua_pushnumber(L, sum / n);
lua_pushnumber(L, sum);
return 2;
}
static int sayHelloFunc(lua_State* L)
{
printf("hello world!");
return 0;
}
static const struct luaL_Reg myLib[] =
{
{"average", averageFunc},
{"sayHello", sayHelloFunc},
{NULL, NULL}
};
int luaopen_TestDll(lua_State *L)
{
luaL_register(L, "ss", myLib);
return 1;
}
TestDll.h
Code: Select all
#pragma once
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#ifdef LUA_API
#undef LUA_API
#endif
#ifdef LUA_EXPORTS
#define LUA_API __declspec(dllexport)
#else
#define LUA_API __declspec(dllimport)
#endif
extern "C" LUA_API int luaopen_TestDll(lua_State *L);
(Some warnings appear while compiling this... I've never written dlls before)