Skip to content

Commit

Permalink
virtual funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
DEntis-T committed Aug 4, 2024
1 parent 5fdd209 commit 841fd5d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 21 deletions.
56 changes: 55 additions & 1 deletion doc/objclass.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,58 @@ Output:

```
13
```
```

## 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.
Binary file modified scriptfiles/index.ps
Binary file not shown.
12 changes: 6 additions & 6 deletions src/modules/header.inc
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,12 @@ stock dpp_inheritfunc(funcname[],fromfunc[],private=0)
{
dpp_argclasscheck(fromfunc);
dpp_symbolcheck__(funcname);
if(dpp_currentobject != DPP_INVALID_OBJECT_ID)
{
new newvalue[dpp_argcharsize];
format(newvalue,sizeof(newvalue),"DPPOf@%s_%s",dpp_objectname[dpp_currentobject],funcname);
strmid(funcname, newvalue, 0, dpp_argcharsize,dpp_argcharsize);
}
//if(dpp_currentobject != DPP_INVALID_OBJECT_ID)
//{
new newvalue[dpp_argcharsize];
format(newvalue,sizeof(newvalue),"DPPOf@%s_%s",dpp_objectname[dpp_currentobject],funcname);
strmid(funcname, newvalue, 0, dpp_argcharsize,dpp_argcharsize);
//}
new _fromfunc__ = -1;
for(new i; i < dpp_maxfuncs; i++)
{
Expand Down
35 changes: 21 additions & 14 deletions src/modules/interpreter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ var_group_3[1] = "1"

stock dpp_process(line[])
{
/*if(!isnull(line))
{
dpp_error("PROC_LOG :: Line : '%s'",line);
}*/
dpp_hzinc();
#if DPP_LOGPROCESSES == 1
if(dpp_processfunc != dpp_lastvalueprcfunc)
Expand Down Expand Up @@ -3533,25 +3537,28 @@ stock dpp_process(line[])
///////////////////////////////////////////////////////

//dpp_parseline_2
if(!strcmp(tokengroup[0], "public"))
if(dpp_currentobject != DPP_INVALID_OBJECT_ID)
{
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], "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)
Expand Down

0 comments on commit 841fd5d

Please sign in to comment.