In scope of this ticket, we need to implement a module system for P# Interpreter. It is a necessary step in order to divide the existing code into separate, dynamically loadable modules. This includes import() function, that can be called from inside a script. It should return a boolean value (false on any error, or true otherwise). What is more, some 'dummy' module has to be written for tests.
Requirements are:
import() has to check if library is already loaded,
import() should return true on successful library load, or if the module has been already loaded - false otherwise,
import() should take a module name as parameter, then add extension automatically and look for it in some predefined directory
all loaded modules should be kept in some structure (linked list or better a hash map); some mechanisms are already implemented in PH7 Engine,
structure saved in "ph7_vm" has to contain information about: module name, module version, short module description
all these information should be returned by some init() function implemented in module and called from builtin_import()
module should register all its constants and functions
all libraries have to be unloaded on program exit, to free up memory
In scope of this ticket, we need to implement a module system for P# Interpreter. It is a necessary step in order to divide the existing code into separate, dynamically loadable modules. This includes import() function, that can be called from inside a script. It should return a boolean value (false on any error, or true otherwise). What is more, some 'dummy' module has to be written for tests.
Requirements are:
* import() has to check if library is already loaded,
* import() should return true on successful library load, or if the module has been already loaded - false otherwise,
* import() should take a module name as parameter, then add extension automatically and look for it in some predefined directory
* all loaded modules should be kept in some structure (linked list or better a hash map); some mechanisms are already implemented in PH7 Engine,
* structure saved in "ph7_vm" has to contain information about: module name, module version, short module description
* all these information should be returned by some init() function implemented in module and called from builtin_import()
* module should register all its constants and functions
* all libraries have to be unloaded on program exit, to free up memory
* multiplatform (Unix .so & Windows .dll) support
Some code snippet:
<?php
var_dump(import('dummy')); // true, module loaded
var_dump(import('dummy2')); // false - no such module
var_dump(import('dummy')); // true - module already loaded
?>
null
bool(TRUE)
string(30 'Hello world from dummy module!')
<?php
var_dump(dummy_function());
var_dump(import('dummy'));
var_dump(dummy_function());
?>
Above code gives the following output now:
null
bool(TRUE)
string(30 'Hello world from dummy module!')
If we re going into WIN32 api vs unixes. Would it be useful to make wrappers around some few types (e.g. HINSTANCE / FILE * or void *) at least ?
If we re going into WIN32 api vs unixes. Would it be useful to make wrappers around some few types (e.g. `HINSTANCE` / `FILE *` or `void *`) at least ?
No the code is good but if we go further and need to call more and more specific win32 api in the future and as HINSTANCE, for example, is quite common ... Or another approach (if it happens not necessary at all for now), to have specific c with all win32 api implementation and one separated for unixes Makefile caring only about the latter the vs project for former ... but might be early to think that way, just food for future thoughts ... sort of.
No the code is good but if we go further and need to call more and more specific win32 api in the future and as HINSTANCE, for example, is quite common ... Or another approach (if it happens not necessary at all for now), to have specific c with all win32 api implementation and one separated for unixes Makefile caring only about the latter the vs project for former ... but might be early to think that way, just food for future thoughts ... sort of.
In scope of this ticket, we need to implement a module system for P# Interpreter. It is a necessary step in order to divide the existing code into separate, dynamically loadable modules. This includes import() function, that can be called from inside a script. It should return a boolean value (false on any error, or true otherwise). What is more, some 'dummy' module has to be written for tests.
Requirements are:
Some code snippet:
Above code gives the following output now:
Still TODO:
Still TODO:
I think it is fully implemented now by
28dbeeb1ad
&0dc9a04f0e
.If we re going into WIN32 api vs unixes. Would it be useful to make wrappers around some few types (e.g.
HINSTANCE
/FILE *
orvoid *
) at least ?Maybe it is not perfect, but PH7 itself is already multiplatform and I think we want to go for it.
No the code is good but if we go further and need to call more and more specific win32 api in the future and as HINSTANCE, for example, is quite common ... Or another approach (if it happens not necessary at all for now), to have specific c with all win32 api implementation and one separated for unixes Makefile caring only about the latter the vs project for former ... but might be early to think that way, just food for future thoughts ... sort of.
I hope there won't be much more WinAPI in use.