zoukankan      html  css  js  c++  java
  • lua调用dll导出的函数

    hello.dll

    #include "pch.h"
    #include "lua.hpp"
    
    #pragma comment(lib, "lua.lib")
    
    BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
    {
        switch (ul_reason_for_call)
        {
        case DLL_PROCESS_ATTACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
        }
        return TRUE;
    }
    
    
    extern "C" {
      int hello_a(lua_State* L) {
        printf("hello a
    ");
        return 1;
      }
    
      int hello_b(lua_State* L) {
        printf("hello b
    ");
        return 1;
      }
    
      __declspec(dllexport) LUALIB_API int __stdcall  luaopen_hello(lua_State* L) {
        lua_register(L, "a", hello_a);
        lua_register(L, "b", hello_b);
        return 1;
      }
    }
    

    test.lua

    require("hello")
    
    a()
    b()
    

    测试

    C:UsersajanuwDesktophellox64Release>lua test.lua
    hello a
    hello b
    

    准备工作:

    1. 将lua源码编译一份lua.lib放在hello/下
    2. hello>wsl cp ../lua-5.4.0/src/*.h ../lua-5.4.0/src/*.hpp ./

    打包后的结果:

    hellox64Release>wsl ls *.dll *.lib
    hello.dll  hello.lib
    

    hello.dlltest.lua放在同级目录后> lua test.lua

  • 相关阅读:
    shell 的多进程
    shell 按行读取文件的内容
    2>&1的意思
    >/dev/null 2>&1
    js 变量作用域
    Premiere Pro 中的键盘快捷键
    premiere pro 2019 mac 破解
    js 空语句
    js 数组原型
    js 奇偶判断
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13668224.html
Copyright © 2011-2022 走看看