[OPENBUS-2739] Permitir modo interativo do 'busconsole' e 'busadmin'

[OPENBUS-2740] Tornar o 'busadmin' um 'busconsole' estendido com funções Lua de governaça
- Implementação do suporte multithread no windows.
- Adaptação para compilação no windows.
- Correção de warnings de compilação.

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/trunk@161159 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 15f8de37
......@@ -83,15 +83,15 @@ ifeq "$(TEC_SYSNAME)" "SunOS"
LFLAGS= $(CFLAGS) -xildoff
endif
ifdef USE_STATIC
SLIB:= $(foreach libname, $(LIBS) uuid ssl crypto, ${OPENBUS_HOME}/lib/lib$(libname).a)
ifeq "$(TEC_SYSNAME)" "SunOS"
LIBS:= rt nsl socket resolv
ifeq ($(findstring $(TEC_SYSNAME), Win32 Win64), )
ifdef USE_STATIC
SLIB:= $(foreach libname, $(LIBS) uuid ssl crypto, ${OPENBUS_HOME}/lib/lib$(libname).a)
ifeq "$(TEC_SYSNAME)" "SunOS"
LIBS:= rt nsl socket resolv
else
LIBS:=
endif
else
LIBS:=
endif
else
ifeq ($(findstring $(TEC_SYSNAME), Win32 Win64), )
ifneq "$(TEC_SYSNAME)" "Darwin"
LIBS+= uuid
endif
......
......@@ -37,8 +37,9 @@ static int l_setlogpath (lua_State *L) {
static int pmain (lua_State *L) {
char **argv = (char **)lua_touserdata(L, 2);
int debugmode = argv[0] && argv[1] && strcmp(argv[1], "DEBUG") == 0;
int status;
luapreload_extralibraries(L);
int status = openbuslua_init(L, 1, debugmode);
status = openbuslua_init(L, 1, debugmode);
if (status == LUA_OK) {
lua_pushliteral(L, OPENBUS_PROGNAME);
lua_setglobal(L, "OPENBUS_PROGNAME");
......@@ -56,8 +57,9 @@ static int pmain (lua_State *L) {
lua_pushstring(L, OPENBUS_MAIN);
status = lua_pcall(L, 1, 1, 0);
if (status == LUA_OK) {
int narg;
if (debugmode) ++argv;
int narg = openbuslua_pushargs(L, argv); /* collect arguments */
narg = openbuslua_pushargs(L, argv); /* collect arguments */
status = openbuslua_call(L, narg+1, 1);
if ( (status == LUA_OK) && lua_isnumber(L, -1) ) return 1;
}
......@@ -78,7 +80,7 @@ int main (int argc, char **argv) {
lua_pushlightuserdata(L, argv); /* 2nd argument */
status = lua_pcall(L, 2, 1, 0);
if (status == LUA_OK) {
result = lua_tointeger(L, -1); /* get result */
result = (int)lua_tointeger(L, -1); /* get result */
} else {
const char *msg = (lua_type(L, -1) == LUA_TSTRING) ? lua_tostring(L, -1)
: NULL;
......
#include <lua.h>
#include <lauxlib.h>
#include <openbuslua.h>
#if defined(_WIN32)
TODO:
#include <errno.h>
#include <process.h>
int prompt_newthread(void (__cdecl *func) (void *), void *data) {
uintptr_t res = _beginthread(func, 0, data);
if (res == -1L) return errno;
return 0;
}
const char *prompt_errormessage(int code) {
switch (code) {
case EAGAIN: return "too many threads";
case EINVAL: return "stack size is incorrect";
case EACCES: return "insufficient resources";
}
return "unexpected error";
}
void OpenBusLuaThread (void *data)
{
lua_State *L = (lua_State *)data;
int status = openbuslua_call(L, 1, 0);
openbuslua_report(L, status);
}
#else
......@@ -11,7 +36,7 @@ TODO:
#include <errno.h>
#include <string.h>
int prompt_newthread(void *(func) (void *), void *data) {
int prompt_newthread(void *(*func) (void *), void *data) {
pthread_t thread;
int res = pthread_create(&thread, NULL, func, data);
if (res) return errno;
......@@ -22,11 +47,6 @@ const char *prompt_errormessage(int code) {
return strerror(code);
}
#endif
#include "openbuslua.h"
static void *OpenBusLuaThread (void *data)
{
lua_State *L = (lua_State *)data;
......@@ -35,6 +55,11 @@ static void *OpenBusLuaThread (void *data)
pthread_exit(NULL);
}
#endif
#include "openbuslua.h"
static void copyPreload (lua_State *from, lua_State *to)
{
/* table is in the stack at index 't' */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment