Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ if(NOT SQ_DISABLE_INSTALLER AND NOT SQ_DISABLE_HEADER_INSTALLER)
include/sqstdmath.h
include/sqstdstring.h
include/sqstdsystem.h
include/sqstdimport.h
include/sqstdmodule.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT Development
)
Expand Down
1 change: 1 addition & 0 deletions doc/source/stdlib/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ THE SOFTWARE.
stdmathlib.rst
stdsystemlib.rst
stdstringlib.rst
stdimportlib.rst
stdauxlib.rst

39 changes: 39 additions & 0 deletions doc/source/stdlib/stdimportlib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.. _stdlib_stdimportlib:

==================
The Import library
==================

the import library implements one single function that allows you to use
the functions and methods of an external Squirrel package.

------------
Squirrel API
------------

++++++++++++++
Global Symbols
++++++++++++++

.. js:function:: import(modulename)

retrieves a table with all the functions and classes exposed from the
module with its given name.
the module name passed in the argument must not have the extension passed
with it (e.g. if the library for the module is called 'my_module.dll',
just use 'import(my_module)').


------------
C API
------------

.. _sqstd_register_importlib:

.. c:function:: SQRESULT sqstd_register_importlib(HSQUIRRELVM v)

:param HSQUIRRELVM v: the target VM
:returns: an SQRESULT
:remarks: The function aspects a table on top of the stack where to register the global library functions.

initialize and register the import library in the give VM.
15 changes: 15 additions & 0 deletions include/sqstdimport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTD_IMPORT_H_
#define _SQSTD_IMPORT_H_

#ifdef __cplusplus
extern "C" {
#endif

SQUIRREL_API SQRESULT sqstd_register_importlib(HSQUIRRELVM v);

#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif //_SQSTD_IMPORT_H_
158 changes: 158 additions & 0 deletions include/sqstdmodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTD_MODULE_H_
#define _SQSTD_MODULE_H_

#include <squirrel.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
/*vm*/
HSQUIRRELVM (*open)(SQInteger initialstacksize);
HSQUIRRELVM (*newthread)(HSQUIRRELVM friendvm, SQInteger initialstacksize);
void (*seterrorhandler)(HSQUIRRELVM v);
void (*close)(HSQUIRRELVM v);
void (*setforeignptr)(HSQUIRRELVM v,SQUserPointer p);
SQUserPointer (*getforeignptr)(HSQUIRRELVM v);
void (*setprintfunc)(HSQUIRRELVM v, SQPRINTFUNCTION printfunc, SQPRINTFUNCTION);
SQPRINTFUNCTION (*getprintfunc)(HSQUIRRELVM v);
SQRESULT (*suspendvm)(HSQUIRRELVM v);
SQRESULT (*wakeupvm)(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
SQInteger (*getvmstate)(HSQUIRRELVM v);

/*compiler*/
SQRESULT (*compile)(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
SQRESULT (*compilebuffer)(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
void (*enabledebuginfo)(HSQUIRRELVM v, SQBool enable);
void (*notifyallexceptions)(HSQUIRRELVM v, SQBool enable);
void (*setcompilererrorhandler)(HSQUIRRELVM v,SQCOMPILERERROR f);

/*stack operations*/
void (*push)(HSQUIRRELVM v,SQInteger idx);
void (*pop)(HSQUIRRELVM v,SQInteger nelemstopop);
void (*poptop)(HSQUIRRELVM v);
void (*remove)(HSQUIRRELVM v,SQInteger idx);
SQInteger (*gettop)(HSQUIRRELVM v);
void (*settop)(HSQUIRRELVM v,SQInteger newtop);
SQRESULT (*reservestack)(HSQUIRRELVM v,SQInteger nsize);
SQInteger (*cmp)(HSQUIRRELVM v);
void (*move)(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);

/*object creation handling*/
SQUserPointer (*newuserdata)(HSQUIRRELVM v,SQUnsignedInteger size);
void (*newtable)(HSQUIRRELVM v);
void (*newarray)(HSQUIRRELVM v,SQInteger size);
void (*newclosure)(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
SQRESULT (*setparamscheck)(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
SQRESULT (*bindenv)(HSQUIRRELVM v,SQInteger idx);
void (*pushstring)(HSQUIRRELVM v,const SQChar *s,SQInteger len);
void (*pushfloat)(HSQUIRRELVM v,SQFloat f);
void (*pushinteger)(HSQUIRRELVM v,SQInteger n);
void (*pushbool)(HSQUIRRELVM v,SQBool b);
void (*pushuserpointer)(HSQUIRRELVM v,SQUserPointer p);
void (*pushnull)(HSQUIRRELVM v);
SQObjectType (*gettype)(HSQUIRRELVM v,SQInteger idx);
SQInteger (*getsize)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getbase)(HSQUIRRELVM v,SQInteger idx);
SQBool (*instanceof)(HSQUIRRELVM v);
SQRESULT (*tostring)(HSQUIRRELVM v,SQInteger idx);
void (*tobool)(HSQUIRRELVM v, SQInteger idx, SQBool *b);
SQRESULT (*getstring)(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
SQRESULT (*getinteger)(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
SQRESULT (*getfloat)(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
SQRESULT (*getbool)(HSQUIRRELVM v,SQInteger idx,SQBool *b);
SQRESULT (*getstringandsize)(HSQUIRRELVM v,SQInteger idx,const SQChar **c,SQInteger *size);
SQRESULT (*getthread)(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
SQRESULT (*getuserpointer)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
SQRESULT (*getuserdata)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
SQRESULT (*settypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
SQRESULT (*gettypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
void (*setreleasehook)(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
SQChar* (*getscratchpad)(HSQUIRRELVM v,SQInteger minsize);
SQRESULT (*getclosureinfo)(HSQUIRRELVM v,SQInteger idx,SQInteger *nparams,SQInteger *nfreevars);
SQRESULT (*setnativeclosurename)(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
SQRESULT (*setinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
SQRESULT (*getinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag,SQBool throwerror);
SQRESULT (*setclassudsize)(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
SQRESULT (*newclass)(HSQUIRRELVM v,SQBool hasbase);
SQRESULT (*createinstance)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*setattributes)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getattributes)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getclass)(HSQUIRRELVM v,SQInteger idx);
void (*weakref)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getdefaultdelegate)(HSQUIRRELVM v,SQObjectType t);

/*object manipulation*/
void (*pushroottable)(HSQUIRRELVM v);
void (*pushregistrytable)(HSQUIRRELVM v);
void (*pushconsttable)(HSQUIRRELVM v);
SQRESULT (*setroottable)(HSQUIRRELVM v);
SQRESULT (*setconsttable)(HSQUIRRELVM v);
SQRESULT (*newslot)(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
SQRESULT (*deleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQRESULT (*set)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*get)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*rawget)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*rawset)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*rawdeleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQRESULT (*arrayappend)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*arraypop)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQRESULT (*arrayresize)(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
SQRESULT (*arrayreverse)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*arrayremove)(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
SQRESULT (*arrayinsert)(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
SQRESULT (*setdelegate)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getdelegate)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*clone)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*setfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
SQRESULT (*next)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getweakrefval)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*clear)(HSQUIRRELVM v,SQInteger idx);

/*calls*/
SQRESULT (*call)(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
SQRESULT (*resume)(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
const SQChar* (*getlocal)(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
const SQChar* (*getfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
SQRESULT (*throwerror)(HSQUIRRELVM v,const SQChar *err);
void (*reseterror)(HSQUIRRELVM v);
void (*getlasterror)(HSQUIRRELVM v);

/*raw object handling*/
SQRESULT (*getstackobj)(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
void (*pushobject)(HSQUIRRELVM v,HSQOBJECT obj);
void (*addref)(HSQUIRRELVM v,HSQOBJECT *po);
SQBool (*release)(HSQUIRRELVM v,HSQOBJECT *po);
void (*resetobject)(HSQOBJECT *po);
const SQChar* (*objtostring)(const HSQOBJECT *o);
SQBool (*objtobool)(const HSQOBJECT *o);
SQInteger (*objtointeger)(const HSQOBJECT *o);
SQFloat (*objtofloat)(const HSQOBJECT *o);
SQRESULT (*getobjtypetag)(const HSQOBJECT *o,SQUserPointer * typetag);

/*GC*/
SQInteger (*collectgarbage)(HSQUIRRELVM v);

/*serialization*/
SQRESULT (*writeclosure)(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
SQRESULT (*readclosure)(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);

/*mem allocation*/
void* (*malloc)(SQUnsignedInteger size);
void* (*realloc)(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
void (*free)(void *p,SQUnsignedInteger size);

/*debug*/
SQRESULT (*stackinfos)(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
void (*setdebughook)(HSQUIRRELVM v);
} sq_api;

typedef sq_api* HSQAPI;

#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif //_SQSTD_MODULE_H_
6 changes: 3 additions & 3 deletions sq/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ SRCS= sq.c


sq32:
g++ -O2 -fno-exceptions -fno-rtti -o $(OUT) $(SRCS) $(INCZ) $(LIBZ) $(LIB)
g++ -ldl -O2 -fno-exceptions -fno-rtti -o $(OUT) $(SRCS) $(INCZ) $(LIBZ) $(LIB)

sqprof:
g++ -O2 -pg -fno-exceptions -fno-rtti -pie -gstabs -g3 -o $(OUT) $(SRCS) $(INCZ) $(LIBZ) $(LIB)
g++ -ldl -O2 -pg -fno-exceptions -fno-rtti -pie -gstabs -g3 -o $(OUT) $(SRCS) $(INCZ) $(LIBZ) $(LIB)

sq64:
g++ -O2 -m64 -fno-exceptions -fno-rtti -D_SQ64 -o $(OUT) $(SRCS) $(INCZ) $(LIBZ) $(LIB)
g++ -ldl -O2 -m64 -fno-exceptions -fno-rtti -D_SQ64 -o $(OUT) $(SRCS) $(INCZ) $(LIBZ) $(LIB)
2 changes: 2 additions & 0 deletions sq/sq.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <sqstdmath.h>
#include <sqstdstring.h>
#include <sqstdaux.h>
#include <sqstdimport.h>

#ifdef SQUNICODE
#define scfprintf fwprintf
Expand Down Expand Up @@ -321,6 +322,7 @@ int main(int argc, char* argv[])
sqstd_register_systemlib(v);
sqstd_register_mathlib(v);
sqstd_register_stringlib(v);
sqstd_register_importlib(v);

//aux library
//sets error handlers
Expand Down
3 changes: 2 additions & 1 deletion sqstdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ set(SQSTDLIB_SRC sqstdaux.cpp
sqstdrex.cpp
sqstdstream.cpp
sqstdstring.cpp
sqstdsystem.cpp)
sqstdsystem.cpp
sqstdimport.cpp)

if(NOT DISABLE_DYNAMIC)
add_library(sqstdlib SHARED ${SQSTDLIB_SRC})
Expand Down
6 changes: 4 additions & 2 deletions sqstdlib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ OBJS= \
sqstdsystem.o \
sqstdstring.o \
sqstdaux.o \
sqstdrex.o
sqstdrex.o \
sqstdimport.o

SRCS= \
sqstdblob.cpp \
Expand All @@ -25,7 +26,8 @@ SRCS= \
sqstdsystem.cpp \
sqstdstring.cpp \
sqstdaux.cpp \
sqstdrex.cpp
sqstdrex.cpp \
sqstdimport.cpp


sq32:
Expand Down
Loading