Better SWIG integration: autogen func & attributes

This commit is contained in:
slurdge 2020-06-14 11:32:37 +02:00 committed by Philippe Teuwen
parent 756b624668
commit 538ee4dabb
12 changed files with 887 additions and 1037 deletions

View file

@ -1,4 +1,4 @@
#!/bin/bash
swig -lua -o ../src/pm3_luawrap.c ../include/pm3.h
swig -python -o ../src/pm3_pywrap.c ../include/pm3.h
swig -lua -o ../src/pm3_luawrap.c ../include/pm3.i
swig -python -o ../src/pm3_pywrap.c ../include/pm3.i

View file

@ -1,4 +1,4 @@
local pm3 = require("pm3")
p=pm3.device()
--p.console("hw status") ??
p.console(p, "hw status")
p:console("hw status")
print(p.name)

View file

@ -3,4 +3,4 @@
import pm3
p=pm3.device()
p.console("hw status")
print("Device:", p.get_name())
print("Device:", p.name)

View file

@ -1,56 +1,11 @@
#ifndef LIBPM3_H
#define LIBPM3_H
#ifdef SWIG
%module pm3
%{
/* Include the header in the wrapper code */
#include "pm3.h"
%}
/* Strip "pm3_" from API functions for SWIG */
%rename("%(strip:[pm3_])s") "";
%feature("immutable","1") pm3_current_dev;
struct pm3_device { };
%extend pm3_device {
pm3_device() {
printf("SWIG pm3_device constructor, get current pm3\n");
_embedded = 1;
return pm3_get_current_dev();
}
pm3_device(char *port) {
printf("SWIG pm3_device constructor with port, open pm3\n");
_embedded = 0;
return pm3_open(port);
}
~pm3_device() {
if (_embedded) {
printf("SWIG pm3_device destructor, nothing to do\n");
} else {
printf("SWIG pm3_device destructor, close pm3\n");
pm3_close($self);
}
}
int console(char *cmd) {
return pm3_console($self, cmd);
}
char *get_name() {
return pm3_get_name($self);
}
}
//%nodefaultctor pm3_device;
//%nodefaultdtor pm3_device;
/* Parse the header file to generate wrappers */
#endif // SWIG
// TODO better than this global?
int _embedded;
typedef struct pm3_device pm3_device;
pm3_device* pm3_open(char *port);
int pm3_console(pm3_device* dev, char *cmd);
char *pm3_get_name(pm3_device* dev);
void pm3_close(pm3_device* dev);
pm3_device* pm3_get_current_dev(void);
int pm3_device_console(pm3_device* dev, char *cmd);
char *pm3_device_name_get(pm3_device* dev);
void pm3_device_close(pm3_device* dev);
pm3_device* pm3_device_get_current_dev(void);
#endif // LIBPM3_H

39
client/include/pm3.i Normal file
View file

@ -0,0 +1,39 @@
%module pm3
%{
/* Include the header in the wrapper code */
#include "pm3.h"
#include "comms.h"
%}
/* Strip "pm3_" from API functions for SWIG */
%rename("%(strip:[pm3_])s") "";
%feature("immutable","1") pm3_current_dev;
typedef struct {
%extend {
pm3_device() {
printf("SWIG pm3_device constructor, get current pm3\n");
pm3_device * p = pm3_device_get_current_dev();
p->script_embedded = 1;
return p;
}
pm3_device(char *port) {
printf("SWIG pm3_device constructor with port, open pm3\n");
pm3_device * p = pm3_open(port);
p->script_embedded = 1;
return p;
}
~pm3_device() {
if ($self->script_embedded) {
printf("SWIG pm3_device destructor, nothing to do\n");
} else {
printf("SWIG pm3_device destructor, close pm3\n");
pm3_device_close($self);
}
}
int console(char *cmd);
char const * const name;
}
} pm3_device;
//%nodefaultctor device;
//%nodefaultdtor device;
/* Parse the header file to generate wrappers */

View file

@ -2,5 +2,5 @@
local pm3 = require("pm3")
p=pm3.device("/dev/ttyACM0")
--p.console("hw status") ??
p.console(p, "hw status")
p:console("hw status")
print(p.name)

View file

@ -3,4 +3,4 @@
import pm3
p=pm3.device("/dev/ttyACM0")
p.console("hw status")
print("Device:", p.get_name())
print("Device:", p.name)

View file

@ -68,6 +68,7 @@ extern communication_arg_t conn;
typedef struct pm3_device pm3_device;
struct pm3_device {
communication_arg_t *conn;
int script_embedded;
};
void *uart_receiver(void *targ);

View file

@ -1,24 +1,85 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 4.0.1
# Version 3.0.12
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info as _swig_python_version_info
if _swig_python_version_info < (2, 7, 0):
raise RuntimeError("Python 2.7 or later required")
# Import the low-level C/C++ module
if __package__ or "." in __name__:
from . import _pm3
if _swig_python_version_info >= (2, 7, 0):
def swig_import_helper():
import importlib
pkg = __name__.rpartition('.')[0]
mname = '.'.join((pkg, '_pm3')).lstrip('.')
try:
return importlib.import_module(mname)
except ImportError:
return importlib.import_module('_pm3')
_pm3 = swig_import_helper()
del swig_import_helper
elif _swig_python_version_info >= (2, 6, 0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_pm3', [dirname(__file__)])
except ImportError:
import _pm3
return _pm3
try:
_mod = imp.load_module('_pm3', fp, pathname, description)
finally:
if fp is not None:
fp.close()
return _mod
_pm3 = swig_import_helper()
del swig_import_helper
else:
import _pm3
del _swig_python_version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
try:
import builtins as __builtin__
except ImportError:
import __builtin__
def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
if (name == "thisown"):
return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name, None)
if method:
return method(self, value)
if (not static):
if _newclass:
object.__setattr__(self, name, value)
else:
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self, class_type, name, value):
return _swig_setattr_nondynamic(self, class_type, name, value, 0)
def _swig_getattr(self, class_type, name):
if (name == "thisown"):
return self.this.own()
method = class_type.__swig_getmethods__.get(name, None)
if method:
return method(self)
raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
def _swig_repr(self):
try:
strthis = "proxy of " + self.this.__repr__()
@ -26,73 +87,38 @@ def _swig_repr(self):
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except __builtin__.Exception:
class _object:
pass
_newclass = 0
def _swig_setattr_nondynamic_instance_variable(set):
def set_instance_attr(self, name, value):
if name == "thisown":
self.this.own(value)
elif name == "this":
set(self, name, value)
elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
set(self, name, value)
else:
raise AttributeError("You cannot add instance attributes to %s" % self)
return set_instance_attr
def _swig_setattr_nondynamic_class_variable(set):
def set_class_attr(cls, name, value):
if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
set(cls, name, value)
else:
raise AttributeError("You cannot add class attributes to %s" % cls)
return set_class_attr
def _swig_add_metaclass(metaclass):
"""Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
def wrapper(cls):
return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
return wrapper
class _SwigNonDynamicMeta(type):
"""Meta class to enforce nondynamic attributes (no new attributes) for a class"""
__setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)
class device(object):
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
class device(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, device, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, device, name)
__repr__ = _swig_repr
def __init__(self, *args):
_pm3.device_swiginit(self, _pm3.new_device(*args))
this = _pm3.new_device(*args)
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
__swig_destroy__ = _pm3.delete_device
__del__ = lambda self: None
def console(self, cmd):
return _pm3.device_console(self, cmd)
__swig_getmethods__["name"] = _pm3.device_name_get
if _newclass:
name = _swig_property(_pm3.device_name_get)
device_swigregister = _pm3.device_swigregister
device_swigregister(device)
def get_name(self):
return _pm3.device_get_name(self)
# Register device in _pm3:
_pm3.device_swigregister(device)
# This file is compatible with both classic and new-style classes.
def open(port):
return _pm3.open(port)
def console(dev, cmd):
return _pm3.console(dev, cmd)
def get_name(dev):
return _pm3.get_name(dev)
def close(dev):
return _pm3.close(dev)
def get_current_dev():
return _pm3.get_current_dev()
cvar = _pm3.cvar

View file

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
* Version 3.0.12
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
@ -185,7 +185,6 @@
/* Flags for pointer conversions */
#define SWIG_POINTER_DISOWN 0x1
#define SWIG_CAST_NEW_MEMORY 0x2
#define SWIG_POINTER_NO_NULL 0x4
/* Flags for new pointer objects */
#define SWIG_POINTER_OWN 0x1
@ -714,23 +713,6 @@ SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
}
#endif
/* Errors in SWIG */
#define SWIG_UnknownError -1
#define SWIG_IOError -2
#define SWIG_RuntimeError -3
#define SWIG_IndexError -4
#define SWIG_TypeError -5
#define SWIG_DivisionByZero -6
#define SWIG_OverflowError -7
#define SWIG_SyntaxError -8
#define SWIG_ValueError -9
#define SWIG_SystemError -10
#define SWIG_AttributeError -11
#define SWIG_MemoryError -12
#define SWIG_NullReferenceError -13
/* -----------------------------------------------------------------------------
* luarun.swg
*
@ -913,8 +895,8 @@ typedef struct swig_elua_entry {
* -------------------------------------------------------------------------- */
/* Push the string STR on the Lua stack, like lua_pushstring, but
prefixed with the location of the innermost Lua call-point
(as formatted by luaL_where). */
prefixed with the the location of the innermost Lua call-point
(as formated by luaL_where). */
SWIGRUNTIME void
SWIG_Lua_pusherrstring (lua_State *L, const char *str)
{
@ -924,8 +906,8 @@ SWIG_Lua_pusherrstring (lua_State *L, const char *str)
}
/* Push a formatted string generated from FMT and following args on
the Lua stack, like lua_pushfstring, but prefixed with the
location of the innermost Lua call-point (as formatted by luaL_where). */
the Lua stack, like lua_pushfstring, but prefixed with the the
location of the innermost Lua call-point (as formated by luaL_where). */
SWIGRUNTIME void
SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...)
{
@ -1022,7 +1004,7 @@ to tell the two structures apart within SWIG, other than by looking at the type
typedef struct {
swig_type_info *type;
int own; /* 1 if owned & must be destroyed */
char data[1]; /* arbitrary amount of data */
char data[1]; /* arbitary amount of data */
} swig_lua_rawdata;
/* Common SWIG API */
@ -1074,7 +1056,7 @@ typedef struct {
#define SWIG_isptrtype(L,I) (lua_isuserdata(L,I) || lua_isnil(L,I))
#ifdef __cplusplus
/* Special helper for member function pointers
/* Special helper for member function pointers
it gets the address, casts it, then dereferences it */
/*#define SWIG_mem_fn_as_voidptr(a) (*((char**)&(a))) */
#endif
@ -1177,7 +1159,7 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
lua_pop(L,1); /*remove nil */
lua_newtable(L);
SWIG_Lua_elua_emulate_register(L,entry->value.value.table);
}
}
if(is_metatable) {
assert(lua_istable(L,-1));
lua_pushvalue(L,-1);
@ -1186,11 +1168,11 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
break;
case LUA_TUSERDATA:
if(entry->value.value.userdata.member)
if(entry->value.value.userdata.member)
SWIG_NewMemberObj(L,entry->value.value.userdata.pvalue,
entry->value.value.userdata.lvalue,
*(entry->value.value.userdata.ptype));
else
else
SWIG_NewPointerObj(L,entry->value.value.userdata.pvalue,
*(entry->value.value.userdata.ptype),0);
break;
@ -1235,7 +1217,7 @@ SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L)
}
assert(lua_gettop(L) == 2);
return 1;
fail:
lua_error(L);
return 0;
@ -1253,7 +1235,7 @@ SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L)
lua_pushcfunction(L, SWIG_Lua_emulate_elua_getmetatable);
lua_rawset(L,-3);
lua_pop(L,2);
}
/* END OF REMOVE */
@ -1772,11 +1754,17 @@ SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L)
{
/* there should be 1 param passed in
(1) userdata (not the metatable) */
swig_lua_userdata* userData;
const char *className;
void* userData;
assert(lua_isuserdata(L,1)); /* just in case */
userData = (swig_lua_userdata*)lua_touserdata(L,1); /* get the userdata address */
userData = lua_touserdata(L,1); /* get the userdata address for later */
lua_getmetatable(L,1); /* get the meta table */
assert(lua_istable(L,-1)); /* just in case */
lua_pushfstring(L, "<userdata of type '%s' at %p>", userData->type->str, userData->ptr);
lua_getfield(L, -1, ".type");
className = lua_tostring(L, -1);
lua_pushfstring(L, "<%s userdata: %p>", className, userData);
return 1;
}
@ -1788,7 +1776,7 @@ SWIGINTERN int SWIG_Lua_class_disown(lua_State *L)
swig_lua_userdata *usr;
assert(lua_isuserdata(L,-1)); /* just in case */
usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
usr->own = 0; /* clear our ownership */
return 0;
}
@ -1897,7 +1885,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname)
Each class structure has a list of pointers to the base class structures.
This function fills them.
It cannot be done at compile time, as this will not work with hireachies
spread over more than one swig file.
spread over more than one swig file.
Therefore it must be done at runtime, querying the SWIG type system.
*/
SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss)
@ -2131,11 +2119,11 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
lua_checkstack(L,5);
numargs = lua_gettop(L); /* number of arguments to pass to actual metamethod */
/* Get upvalues from closure */
lua_pushvalue(L, lua_upvalueindex(1)); /*Get function name*/
metamethod_name_idx = lua_gettop(L);
lua_pushvalue(L, lua_upvalueindex(2));
clss = (const swig_lua_class*)(lua_touserdata(L,-1));
lua_pop(L,1); /* remove lightuserdata with clss from stack */
@ -2167,7 +2155,7 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
/* metamethod name - on the top of the stack */
assert(lua_isstring(L,-1));
key_index = lua_gettop(L);
/* Check whether method is already defined in metatable */
@ -2177,7 +2165,7 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
lua_pop(L,1);
return -1;
}
lua_pop(L,1);
lua_pop(L,1);
/* Iterating over immediate bases */
for(i=0;clss->bases[i];i++)
@ -2187,13 +2175,13 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
lua_pushvalue(L, key_index);
lua_rawget(L, -2);
if( !lua_isnil(L,-1) ) {
lua_pushvalue(L, key_index);
lua_pushvalue(L, key_index);
/* Add proxy function */
lua_pushvalue(L, key_index); /* first closure value is function name */
lua_pushlightuserdata(L, clss); /* second closure value is swig_lua_class structure */
lua_pushcclosure(L, SWIG_Lua_resolve_metamethod, 2);
lua_rawset(L, metatable_index);
success = 1;
}
@ -2204,7 +2192,7 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
break;
}
return success;
return success;
}
SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss)
@ -2492,12 +2480,7 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type
{
swig_lua_userdata *usr;
swig_cast_info *cast;
/* special case: lua nil => NULL pointer */
if (lua_isnil(L,index))
{
*ptr=0;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
}
if (lua_isnil(L,index)){*ptr=0; return SWIG_OK;} /* special case: lua nil => NULL pointer */
usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
if (usr)
{
@ -2543,7 +2526,7 @@ SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_t
memcpy(raw->data,ptr,size); /* copy the data */
SWIG_Lua_AddMetatable(L,type); /* add metatable */
}
/* converts a packed userdata. user for member fn pointers only */
SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L,int index,void *ptr,size_t size,swig_type_info *type)
{
@ -2592,7 +2575,7 @@ SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) {
switch(constants[i].type) {
case SWIG_LUA_INT:
lua_pushstring(L,constants[i].name);
lua_pushinteger(L,(lua_Integer)constants[i].lvalue);
lua_pushinteger(L,(lua_Number)constants[i].lvalue);
lua_rawset(L,-3);
break;
case SWIG_LUA_FLOAT:
@ -2603,7 +2586,7 @@ SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) {
case SWIG_LUA_CHAR:
lua_pushstring(L,constants[i].name);
{
char c = (char)constants[i].lvalue;
char c = constants[i].lvalue;
lua_pushlstring(L,&c,1);
}
lua_rawset(L,-3);
@ -2642,7 +2625,7 @@ Unfortunately lua keeps changing its APIs, so we need a conditional compile
In lua 5.0.X it's lua_dostring()
In lua 5.1.X it's luaL_dostring()
*/
SWIGINTERN int
SWIGINTERN int
SWIG_Lua_dostring(lua_State *L, const char *str) {
int ok,top;
if (str==0 || str[0]==0) return 0; /* nothing to do */
@ -2657,7 +2640,7 @@ SWIG_Lua_dostring(lua_State *L, const char *str) {
}
lua_settop(L,top); /* restore the stack */
return ok;
}
}
#ifdef __cplusplus
}
@ -2684,12 +2667,14 @@ static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0};
/* Include the header in the wrapper code */
#include "pm3.h"
#include "comms.h"
SWIGINTERN struct pm3_device *new_pm3_device__SWIG_0(void){
printf("SWIG pm3_device constructor, get current pm3\n");
_embedded = 1;
return pm3_get_current_dev();
}
SWIGINTERN pm3_device *new_pm3_device__SWIG_0(void){
printf("SWIG pm3_device constructor, get current pm3\n");
pm3_device * p = pm3_device_get_current_dev();
p->script_embedded = 1;
return p;
}
SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
int ret = lua_isstring(L, idx);
@ -2698,34 +2683,29 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
return ret;
}
SWIGINTERN struct pm3_device *new_pm3_device__SWIG_1(char *port){
printf("SWIG pm3_device constructor with port, open pm3\n");
_embedded = 0;
return pm3_open(port);
}
SWIGINTERN void delete_pm3_device(struct pm3_device *self){
if (_embedded) {
printf("SWIG pm3_device destructor, nothing to do\n");
} else {
printf("SWIG pm3_device destructor, close pm3\n");
pm3_close(self);
SWIGINTERN pm3_device *new_pm3_device__SWIG_1(char *port){
printf("SWIG pm3_device constructor with port, open pm3\n");
pm3_device * p = pm3_open(port);
p->script_embedded = 1;
return p;
}
SWIGINTERN void delete_pm3_device(pm3_device *self){
if (self->script_embedded) {
printf("SWIG pm3_device destructor, nothing to do\n");
} else {
printf("SWIG pm3_device destructor, close pm3\n");
pm3_device_close(self);
}
}
}
SWIGINTERN int pm3_device_console(struct pm3_device *self,char *cmd){
return pm3_console(self, cmd);
}
SWIGINTERN char *pm3_device_get_name(struct pm3_device *self){
return pm3_get_name(self);
}
#ifdef __cplusplus
extern "C" {
#endif
static int _wrap_new_device__SWIG_0(lua_State* L) {
int SWIG_arg = 0;
struct pm3_device *result = 0 ;
pm3_device *result = 0 ;
SWIG_check_num_args("pm3_device::pm3_device",0,0)
result = (struct pm3_device *)new_pm3_device__SWIG_0();
result = (pm3_device *)new_pm3_device__SWIG_0();
SWIG_NewPointerObj(L,result,SWIGTYPE_p_pm3_device,1); SWIG_arg++;
return SWIG_arg;
@ -2740,12 +2720,12 @@ fail:
static int _wrap_new_device__SWIG_1(lua_State* L) {
int SWIG_arg = 0;
char *arg1 = (char *) 0 ;
struct pm3_device *result = 0 ;
pm3_device *result = 0 ;
SWIG_check_num_args("pm3_device::pm3_device",1,1)
if(!SWIG_lua_isnilstring(L,1)) SWIG_fail_arg("pm3_device::pm3_device",1,"char *");
arg1 = (char *)lua_tostring(L, 1);
result = (struct pm3_device *)new_pm3_device__SWIG_1(arg1);
result = (pm3_device *)new_pm3_device__SWIG_1(arg1);
SWIG_NewPointerObj(L,result,SWIGTYPE_p_pm3_device,1); SWIG_arg++;
return SWIG_arg;
@ -2787,12 +2767,12 @@ static int _wrap_new_device(lua_State* L) {
static int _wrap_device_console(lua_State* L) {
int SWIG_arg = 0;
struct pm3_device *arg1 = (struct pm3_device *) 0 ;
pm3_device *arg1 = (pm3_device *) 0 ;
char *arg2 = (char *) 0 ;
int result;
SWIG_check_num_args("pm3_device::console",2,2)
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("pm3_device::console",1,"struct pm3_device *");
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("pm3_device::console",1,"pm3_device *");
if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("pm3_device::console",2,"char *");
if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_pm3_device,0))){
@ -2812,19 +2792,19 @@ fail:
}
static int _wrap_device_get_name(lua_State* L) {
static int _wrap_device_name_get(lua_State* L) {
int SWIG_arg = 0;
struct pm3_device *arg1 = (struct pm3_device *) 0 ;
pm3_device *arg1 = (pm3_device *) 0 ;
char *result = 0 ;
SWIG_check_num_args("pm3_device::get_name",1,1)
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("pm3_device::get_name",1,"struct pm3_device *");
SWIG_check_num_args("pm3_device::name",1,1)
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("pm3_device::name",1,"pm3_device *");
if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_pm3_device,0))){
SWIG_fail_ptr("device_get_name",1,SWIGTYPE_p_pm3_device);
SWIG_fail_ptr("device_name_get",1,SWIGTYPE_p_pm3_device);
}
result = (char *)pm3_device_get_name(arg1);
result = (char *)pm3_device_name_get(arg1);
lua_pushstring(L,(const char *)result); SWIG_arg++;
return SWIG_arg;
@ -2837,7 +2817,7 @@ fail:
static void swig_delete_device(void *obj) {
struct pm3_device *arg1 = (struct pm3_device *) obj;
pm3_device *arg1 = (pm3_device *) obj;
delete_pm3_device(arg1);
}
static int _proxy__wrap_new_device(lua_State *L) {
@ -2849,11 +2829,11 @@ static int _proxy__wrap_new_device(lua_State *L) {
return 1;
}
static swig_lua_attribute swig_device_attributes[] = {
{ "name", _wrap_device_name_get, SWIG_Lua_set_immutable },
{0,0,0}
};
static swig_lua_method swig_device_methods[]= {
{ "console", _wrap_device_console},
{ "get_name", _wrap_device_get_name},
{0,0}
};
static swig_lua_method swig_device_meta[] = {
@ -2885,166 +2865,13 @@ static swig_lua_class *swig_device_bases[] = {0};
static const char *swig_device_base_names[] = {0};
static swig_lua_class _wrap_class_device = { "device", "device", &SWIGTYPE_p_pm3_device,_proxy__wrap_new_device, swig_delete_device, swig_device_methods, swig_device_attributes, &swig_device_Sf_SwigStatic, swig_device_meta, swig_device_bases, swig_device_base_names };
static int _wrap__embedded_set(lua_State* L) {
int SWIG_arg = 0;
int arg1 ;
SWIG_check_num_args("_embedded",1,1)
if(!lua_isnumber(L,1)) SWIG_fail_arg("_embedded",1,"int");
arg1 = (int)lua_tonumber(L, 1);
_embedded = arg1;
return SWIG_arg;
if(0) SWIG_fail;
fail:
lua_error(L);
return SWIG_arg;
}
static int _wrap__embedded_get(lua_State* L) {
int SWIG_arg = 0;
int result;
SWIG_check_num_args("_embedded",0,0)
result = (int)_embedded;
lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
return SWIG_arg;
if(0) SWIG_fail;
fail:
lua_error(L);
return SWIG_arg;
}
static int _wrap_open(lua_State* L) {
int SWIG_arg = 0;
char *arg1 = (char *) 0 ;
pm3_device *result = 0 ;
SWIG_check_num_args("pm3_open",1,1)
if(!SWIG_lua_isnilstring(L,1)) SWIG_fail_arg("pm3_open",1,"char *");
arg1 = (char *)lua_tostring(L, 1);
result = (pm3_device *)pm3_open(arg1);
SWIG_NewPointerObj(L,result,SWIGTYPE_p_pm3_device,0); SWIG_arg++;
return SWIG_arg;
if(0) SWIG_fail;
fail:
lua_error(L);
return SWIG_arg;
}
static int _wrap_console(lua_State* L) {
int SWIG_arg = 0;
pm3_device *arg1 = (pm3_device *) 0 ;
char *arg2 = (char *) 0 ;
int result;
SWIG_check_num_args("pm3_console",2,2)
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("pm3_console",1,"pm3_device *");
if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("pm3_console",2,"char *");
if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_pm3_device,0))){
SWIG_fail_ptr("console",1,SWIGTYPE_p_pm3_device);
}
arg2 = (char *)lua_tostring(L, 2);
result = (int)pm3_console(arg1,arg2);
lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
return SWIG_arg;
if(0) SWIG_fail;
fail:
lua_error(L);
return SWIG_arg;
}
static int _wrap_get_name(lua_State* L) {
int SWIG_arg = 0;
pm3_device *arg1 = (pm3_device *) 0 ;
char *result = 0 ;
SWIG_check_num_args("pm3_get_name",1,1)
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("pm3_get_name",1,"pm3_device *");
if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_pm3_device,0))){
SWIG_fail_ptr("get_name",1,SWIGTYPE_p_pm3_device);
}
result = (char *)pm3_get_name(arg1);
lua_pushstring(L,(const char *)result); SWIG_arg++;
return SWIG_arg;
if(0) SWIG_fail;
fail:
lua_error(L);
return SWIG_arg;
}
static int _wrap_close(lua_State* L) {
int SWIG_arg = 0;
pm3_device *arg1 = (pm3_device *) 0 ;
SWIG_check_num_args("pm3_close",1,1)
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("pm3_close",1,"pm3_device *");
if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_pm3_device,0))){
SWIG_fail_ptr("close",1,SWIGTYPE_p_pm3_device);
}
pm3_close(arg1);
return SWIG_arg;
if(0) SWIG_fail;
fail:
lua_error(L);
return SWIG_arg;
}
static int _wrap_get_current_dev(lua_State* L) {
int SWIG_arg = 0;
pm3_device *result = 0 ;
SWIG_check_num_args("pm3_get_current_dev",0,0)
result = (pm3_device *)pm3_get_current_dev();
SWIG_NewPointerObj(L,result,SWIGTYPE_p_pm3_device,0); SWIG_arg++;
return SWIG_arg;
if(0) SWIG_fail;
fail:
lua_error(L);
return SWIG_arg;
}
static swig_lua_attribute swig_SwigModule_attributes[] = {
{ "_embedded", _wrap__embedded_get, _wrap__embedded_set },
{0,0,0}
};
static swig_lua_const_info swig_SwigModule_constants[]= {
{0,0,0,0,0,0}
};
static swig_lua_method swig_SwigModule_methods[]= {
{ "open", _wrap_open},
{ "console", _wrap_console},
{ "get_name", _wrap_get_name},
{ "close", _wrap_close},
{ "get_current_dev", _wrap_get_current_dev},
{0,0}
};
static swig_lua_class* swig_SwigModule_classes[]= {
@ -3069,7 +2896,7 @@ static swig_lua_namespace swig_SwigModule = {
/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
static swig_type_info _swigt__p_pm3_device = {"_p_pm3_device", "struct pm3_device *|pm3_device *", 0, 0, (void*)&_wrap_class_device, 0};
static swig_type_info _swigt__p_pm3_device = {"_p_pm3_device", "pm3_device *", 0, 0, (void*)&_wrap_class_device, 0};
static swig_type_info *swig_type_initial[] = {
&_swigt__p_pm3_device,
@ -3184,7 +3011,7 @@ SWIG_InitializeModule(void *clientdata) {
/* Now work on filling in swig_module.types */
#ifdef SWIGRUNTIME_DEBUG
printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size);
printf("SWIG_InitializeModule: size %d\n", swig_module.size);
#endif
for (i = 0; i < swig_module.size; ++i) {
swig_type_info *type = 0;
@ -3192,7 +3019,7 @@ SWIG_InitializeModule(void *clientdata) {
swig_cast_info *cast;
#ifdef SWIGRUNTIME_DEBUG
printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name);
#endif
/* if there is another module already loaded */
@ -3268,7 +3095,7 @@ SWIG_InitializeModule(void *clientdata) {
for (i = 0; i < swig_module.size; ++i) {
int j = 0;
swig_cast_info *cast = swig_module.cast_initial[i];
printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name);
while (cast->type) {
printf("SWIG_InitializeModule: cast type %s\n", cast->type->name);
cast++;

File diff suppressed because it is too large Load diff

View file

@ -727,7 +727,7 @@ pm3_device* pm3_open(char *port) {
return session.current_device;
}
void pm3_close(pm3_device* dev) {
void pm3_device_close(pm3_device* dev) {
// For now, there is no real device context:
(void) dev;
// Clean up the port
@ -739,17 +739,17 @@ void pm3_close(pm3_device* dev) {
}
}
int pm3_console(pm3_device* dev, char *Cmd) {
int pm3_device_console(pm3_device* dev, char *Cmd) {
// For now, there is no real device context:
(void) dev;
return CommandReceived(Cmd);
}
char *pm3_get_name(pm3_device* dev) {
const char *pm3_device_name_get(pm3_device* dev) {
return dev->conn->serial_port_name;
}
pm3_device* pm3_get_current_dev(void) {
pm3_device* pm3_device_get_current_dev(void) {
return session.current_device;
}
/* ======================================================= */