From 841fd5dc1356492cac565362f5e52548d6b65f53 Mon Sep 17 00:00:00 2001 From: DEntisT Date: Sun, 4 Aug 2024 12:08:20 +0200 Subject: [PATCH] virtual funcs --- doc/objclass.md | 56 +++++++++++++++++++++++++++++++++++- scriptfiles/index.ps | Bin 7099 -> 7099 bytes src/modules/header.inc | 12 ++++---- src/modules/interpreter.inc | 35 +++++++++++++--------- 4 files changed, 82 insertions(+), 21 deletions(-) diff --git a/doc/objclass.md b/doc/objclass.md index e995dec..4ff9170 100644 --- a/doc/objclass.md +++ b/doc/objclass.md @@ -67,4 +67,58 @@ Output: ``` 13 -``` \ No newline at end of file +``` + +## Virtual functions +- Virtual functions are blueprints for creating functions within classes: + +```cpp +using namespace test +{ + void __eat() virtual + { + static[byte]StaticByte=9 + console.println.log("This human is eating") + } + void __eat2() virtual + { + console.println.log("This human is eating again!") + } +} + +class HumanBeing +{ + new[str]name="Mustafa" + public eat=>test::__eat + new[int]age=85 + public eat2=>test::__eat2 +} + +object MeAgain=HumanBeing + +MeAgain.eat() +console.println.log("MeAgain.name is {MeAgain.name}") +console.rawout.log(MeAgain.age) + +void testfunc() private +{ + static[byte]StaticByte2=10 + [quiet] + MeAgain.eat() + [quiet] + MeAgain.eat2() + console.println.log("StaticByte is {StaticByte}") + console.println.log("StaticByte2 is {StaticByte2}") +} + +user.testfunc +``` + +The following line contained within a class will create a new public function `eat` using data of the virtual function `test::__eat`: +```cpp +public eat=>test::__eat +``` + +If you want the new function to be private, just change the `public` modifier to `private`. + +- **NOTE**: The reason you can't just create a function inside a class directly is an internal issue - basically, having a nested interpreter-terminating code block would cause potential issues. \ No newline at end of file diff --git a/scriptfiles/index.ps b/scriptfiles/index.ps index 14e215e426812b84fb34a90512860588b8e3dbd7..0208ea92c4bc4b32f3447a574387ff20ce5116eb 100644 GIT binary patch delta 83 zcmdmOzT14mKgr2PQW8!DrAaxN$qK27CAM}Ysl_E$R`Kyb4i{%$YI$^KUP)|XdaA93 SDHkU~p%IEoqs*-VT2-MH2IID6klFyd30u8 RNo-"); - if(!isnull(funcgroup_inherit[0]) && !isnull(funcgroup_inherit[1])) + if(!strcmp(tokengroup[0], "public")) { - dpp_inheritfunc(funcgroup_inherit[0],funcgroup_inherit[1]); + new funcgroup_inherit[2][64]; + dpp_parseline_2(tokengroup[1],funcgroup_inherit,"=>"); + if(!isnull(funcgroup_inherit[0]) && !isnull(funcgroup_inherit[1])) + { + dpp_inheritfunc(funcgroup_inherit[0],funcgroup_inherit[1]); + } + return 1; } - return 1; - } - if(!strcmp(tokengroup[0], "private")) - { - new funcgroup_inherit[2][64]; - dpp_parseline_2(tokengroup[1],funcgroup_inherit,"->"); - if(!isnull(funcgroup_inherit[0]) && !isnull(funcgroup_inherit[1])) + if(!strcmp(tokengroup[0], "private")) { - dpp_inheritfunc(funcgroup_inherit[0],funcgroup_inherit[1],.private=1); + new funcgroup_inherit[2][64]; + dpp_parseline_2(tokengroup[1],funcgroup_inherit,"=>"); + if(!isnull(funcgroup_inherit[0]) && !isnull(funcgroup_inherit[1])) + { + dpp_inheritfunc(funcgroup_inherit[0],funcgroup_inherit[1],.private=1); + } + return 1; } - return 1; } if(dpp_funcfound == 0)