Enviado em 27/02/2009 - 21:20h
Módulo Lua 5.1.4.
/*===============================================================
**
** DESCRIÇÃO:
** Como criar um módulo(.dll ou .so) para LUA 5.1.4
**
** COMPILE:
** gcc -shared -o mod.so mod.c -llua -Wall
**
** FUNCTION:
** mod.help()
** mod.func1(int, char *)
**
** BY: gokernel - gokernel@hotmail.com
**=================================================================*/
// LUA 5.1.4
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
// Prototype
const luaL_reg my_mod[];
//===========================
// USE IN SCRIPT: mod.help()
//===========================
int mod_help (lua_State* L) {
int c;
printf("LIST OF FUNCTIONS:\n");
for (c=0; my_mod[c].name; c++) {
printf(" mod.%s()\n", my_mod[c].name);
}
return 0;
}
//===============================
// USE IN SCRIPT: mod.func1(10, "?? Hello Wold ??")
//===============================
int mod_func1 (lua_State* L) {
// Verifica se PARAMETROS == 2: no "script.lua"
if ( lua_gettop(L) == 2 ) {
int i = (int)lua_tonumber(L, 1);
char *string = (char *)lua_tostring(L, 2);
int count;
for (count = 0; count < i; count++) {
printf("%d = %s\n", count, string);
}
}
return 0;
}
// Seu pequeno MODULO para LUA 5.1.4
const luaL_reg my_mod[] = {
{"help", mod_help },
{"func1", mod_func1 },
{NULL, NULL }
};
//==========================================
// IMPORTANTE:
// Salve este arquivo com o nome: "mod.c"
//==========================================
LUA_API int luaopen_mod (lua_State* L)
{
luaL_openlib(L, "mod", my_mod, 0); // Carrega o seu MODULO
printf("Gloria a DEUS: O seu modulo foi CARREGADO\n");
return 1;
}
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Visualizar câmeras IP ONVIF no Linux sem necessidade de instalar aplicativos
Atualizar Debian Online de uma Versão para outra
Dica para encontrar diversos jogos Indies criativos
Instalando Discord no Debian 13
Instalar driver Nvidia no Debian 13
Redimensionando, espelhando, convertendo e rotacionando imagens com script
Software livre - será que eu estou tão errado assim? (14)
Boot do PosRog so funciona em notebook (1)