Compare commits

...

3 Commits

Author SHA1 Message Date
Fierelier 55dee42376 Add comments 2023-04-03 19:04:17 +02:00
Fierelier 9d5e6948a7 Change "Running " to "Running new instance of ", to make how modules work more obvious 2023-04-03 19:03:57 +02:00
Fierelier f97cd553a7 Make dofile read bytes instead of string, to allow compiled scripts 2023-04-03 19:03:14 +02:00
3 changed files with 9 additions and 9 deletions

View File

@ -6,13 +6,13 @@ def main():
# Some example code to test the functionality
testpy = mfp.require("test")
testpy.st = "Hello world"
testpy.echo()
testpy.echo() # "Hello world"
testpy["st"] = "Hello world 2"
testpy.echo()
testpy.echo() # "Hello world 2"
testpy = mfp.require("test")
testpy.echo()
testpy.echo() # Will still be "Hello world 2", since the library has been required before.
testpy = mfp.dofile(mfp.p(mfp.sd,"module","test.py")) # Same file as used for mfp.require
testpy.echo()
testpy.echo() # Will be None, as it's a new instance of the library (dofile does not care)
def bootstrap(name,modName):
if name in globals(): return
@ -32,4 +32,4 @@ def bootstrap(name,modName):
bootstrap("mfp","me.fier.python")
init()
if __name__ == '__main__':
main()
main()

View File

@ -34,7 +34,7 @@ def docode(st,name = "Unknown"):
return glb
def dofile(path):
return docode(open(path,encoding="utf-8").read(),path)
return docode(open(path,"rb").read(),path)
def dorequire(name,*args,**kwargs):
for path in paths:
@ -78,4 +78,4 @@ def init(mod,modl,sp,d):
programNameSet = False
paths.append(p(modl.sd,"module","?.py"))
paths.append(p(modl.sd,"module","?","_main.py"))
paths.append(p(modl.sd,"module","?","_main.py"))

View File

@ -1,4 +1,4 @@
print("Running " +mfpl.s)
print("Running new instance of " +mfpl.s)
st = None
def echo():
print(st)
print(st)