extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "luaAPI.h"
#include "lualib.h"
}
#include <iostream>
#include <Windows.h>
static int mu1(lua_State* L)
{
if (lua_gettop(L) == 2 && lua_type(L, 1) == LUA_TNUMBER && lua_type(L, 2) == LUA_TNUMBER)
{
lua_Number x = lua_tonumber(L, 1);
lua_Number y = lua_tonumber(L, 2);
SetCursorPos(x, y);
}
return 0;
}
static int mu2(lua_State* L)
{
POINT p;
GetCursorPos(&p);
lua_pushnumber(L, p.x);
lua_pushnumber(L, p.y);
return 2;
}
static luaL_Reg func[] = {
{"mu1", mu1},
{"mu2", mu2},
{NULL, NULL},
};
extern int luaopen_luaAPI_core(lua_State* L)
{
std::cout << "注册成功" << std::endl;
luaL_openlib(L, "wocao", func, 0);
return 1;
}
int main()
{
lua_State* L = luaL_newstate();
luaL_openlibs(L);
luaL_openlib(L, "wocao", func, 0);
luaL_dostring(L, "print(\"caonima\")");
luaL_dofile(L, "C:\\Users\\Administrator\\source\\repos\\luaAPI\\x64\\Debug\\main.lua");
}