android LUA 调用C 编译的.SO动态库

测试环境 c4droid 懒人精灵 雷电模拟器 PC DNK-build

DNK-build 编译文件目录
android LUA 调用C 编译的.SO动态库_第1张图片
android LUA 调用C 编译的.SO动态库_第2张图片

SRC目录保存 要编译的.C文件 luabib目录保存 LUA支持库以及 需要的.SO文件

下面展示 MyLib.c代码

// An highlighted block
#include 
#include 
#include 
#include 

#include //pwrite64        头文件
#include //atof 头文件
#include // tolower toupper 头文件

#include 
#include 
#include 
#include 
#define MAX_PATH  1024
#include 

static int PagGamePID = 0;

unsigned long hexToDec(const char* addr) {
    unsigned long num;
    sscanf(addr, "%lx", &num);//4294967296
    return num;
}
char* strlowr(char* str)
{
    char* orign = str;
    for (; *str != '\0'; str++)
        *str = tolower(*str);
    return orign;
}
char* strupr(char* str)
{
    char* orign = str;
    for (; *str != '\0'; str++)
        *str = toupper(*str);
    return orign;
}

int FindPidByProcessName(const char* process_name) {
    int ProcessDirID = 0;
    pid_t   pid = -3;
    FILE* fp = NULL;
    char filename[MAX_PATH] = { 0 };
    char  cmdline[MAX_PATH] = { 0 };

    struct dirent* entry = NULL;

    if (process_name == NULL) {
        return -1;
    }

    DIR* dir = opendir("/proc");
    if (dir == NULL) {
        return -2;
    }

    while ((entry = readdir(dir)) != NULL) {
        ProcessDirID = atoi(entry->d_name);//将数字文件名转换为int ,转换失败的话返回0;
        if (ProcessDirID != 0) {
            snprintf(filename, MAX_PATH, "/proc/%d/cmdline", ProcessDirID);// 文件/proc//cmdline 为进程的启动命令行。安卓平台的为app包名;
            fp = fopen(filename, "r");
            if (fp)
            {
                fgets(cmdline, sizeof(cmdline), fp);
                fclose(fp);
                if (strncmp(process_name, cmdline, strlen(process_name)) == 0)
                {
                    pid = ProcessDirID;
                    break;
                }
            }
        }
    }
    closedir(dir);
    return pid;
}

static int Add(lua_State* L) {
    double d1 = luaL_checknumber(L, 1);
    double d2 = luaL_checknumber(L, 2);
    lua_pushnumber

你可能感兴趣的:(LUA,调用C,二进制文件,c++,linux,ndk)