lua调用syslog; 使用C注册lua方法

  • Post author:
  • Post category:其他


测试代码:

lua

#!/usr/bin/lua

require “lrsyslog”

print(“————————“)

losslog(“12|34|56|78|10000|gggggggggg|aaaaaaaaaaa|bbbbbbbbbbbbbbbb|ccccccccc|99999|222”)

——————————————————————————以下 lsyslog.c 代码片段———————————————————-

#include <syslog.h>

#include <ctype.h>

#include <string.h>

#include “lua.h”

#include “lualib.h”

#include “lauxlib.h”

static int l_lapplog(lua_State *L)

{

const char* log_content = luaL_checkstring(L, 1);

if (NULL == log_content) { return 0; }

syslog(LOG_DEBUG, “LAPPLOG|%s”, log_content);

return 0;

}

static int l_losslog(lua_State *L)

{

const char* log_content = luaL_checkstring(L, 1);

if (NULL == log_content) { return 0; }

syslog(LOG_DEBUG, “LOSSLOG|%s”, log_content);

return 0;

}

static const luaL_reg R[] =

{



{“losslog”,


l_losslog},



{“lapplog”,


l_lapplog},



{NULL,


NULL}

};

int luaopen_lrsyslog(lua_State *L)

{

lua_register(L, “losslog”, l_losslog);

lua_register(L, “lapplog”, l_lapplog);

return 0;

}



版权声明:本文为hubaolin原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。