Skip to content
Draft
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
89 changes: 89 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import zbrush

gScriptVersion = 1.0


def check_script_version():
fred = 1
gScriptVersion = zbrush.ZbrushInfo(0)


def test_func(arg, arg2):
print(arg)
arg2 = arg + 1


def fred():
zbrush.MemCreate("other", 100, "A")
memblock = zbrush.MemCreate("memblock", 100, "A")
zbrush.MemWrite(memblock, 0, "A", 1)
goof = zbrush.MemRead(memblock, 0, "A", 1) # noqa
test = zbrush.ToolGetActiveIndex()
subtooltst = zbrush.GetSubToolIndex(2)
allowed = max(1, 2)
barney = 1
josh = test_return_string(barney)
print(josh)
xxxx = test_return_float(barney)
print(xxxx)
wilma = test_return_int(barney)
pebbles = "a"
bam_bam = "b"
"""random internal comment"""


def test_loop() -> int:
for x in range(10):
if x == 5:
return x
else:
if x in [3, 4]:
continue
print(x)


def array_contains(arr, val) -> int:
loopsize = zbrush.VarSize(arr)
result = loopsize
# result = 0
# for x in range(loopsize):
# if arr[x] == val:
# """todo return 1"""
# result = 1
# break
return result


def test_array_contains(arr, val) -> int:
result = array_contains(arr, val)


# todo: figure out how to handle retruns in cases inside loops and whiles


def test_while(iterations, cutoff) -> int:
val = 0
"""random internal comment"""
otherval = 1.0
while val < iterations:
if val == cutoff:
return val
val += 1


def test_return_string(arg) -> str:
"""convert 'return val' to return an automatic value"""
val = arg + "xxx"
return val


def test_return_float(arg) -> float:
"""convert 'return val' to return an automatic value"""
val = arg + 1.0
return val


def test_return_int(arg) -> int:
"""convert 'return val' to return an automatic value"""
val = arg + 1
return val
122 changes: 122 additions & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
transpiled with zsc 0.1.0
from: test.py
*/

// automatic return vars

[RoutineDef, check_script_version,
[VarSet, gScriptVersion, [ZbrushInfo, 0]]
] // end check_script_version


[RoutineDef, test_func,
[RoutineCall, print, #arg]
, // args
arg, arg2
] // end test_func


[RoutineDef, fred,
[MemCreate, , "other", 100, "A"]
// blockID = memblock
[VarSet, memblock, [MemCreate, memblock, 100, 'A']]
[MemWrite, , memblock, 0, "A", 1]
[VarSet, goof, [MemRead, memblock, 0, 'A', 1]]
[VarSet, test, [ToolGetActiveIndex]]
[VarSet, subtooltst, [GetSubToolIndex, 2]]
[VarSet, allowed, [MAX, , 1, 2]]
[RoutineCall, test_return_string, #barney, josh]
[RoutineCall, print, #josh]
[RoutineCall, test_return_float, #barney, xxxx]
[RoutineCall, print, #xxxx]
[RoutineCall, test_return_int, #barney, wilma]
// random internal comment
] // end fred


[RoutineDef, test_loop,

[Loop, 10,

[If, ([Var, x] = 5),
// then...
[Exit]
, // else

[If, ([Var, x]34),
// then...
[LoopContinue]
, // else

]
[RoutineCall, print, #x]
]
,
x ] // loop end
] // end test_loop


[RoutineDef, array_contains,
[VarSet, loopsize, [VarSize, #arr]]
[Exit]
, // args
arr, val, _auto_return
] // end array_contains


[RoutineDef, test_array_contains,
[RoutineCall, array_contains, #arr, #val, result]
, // args
arr, val
] // end test_array_contains


[RoutineDef, test_while,
// random internal comment

[Loop, 65534,

[If, ([Var, val] = [Var, cutoff]),
// then...
[Exit]
, // else

]
[VarAdd, val, 1]

[If, ([Var, val] < [Var, iterations]),
// then...
[LoopContinue]
, // else
[LoopExit]
]
,
WhileLoop ] // loop end
, // args
iterations, cutoff
] // end test_while


// convert 'return val' to return an automatic value
[RoutineDef, test_return_string,
[Exit]
, // args
arg, _auto_return
] // end test_return_string


// convert 'return val' to return an automatic value
[RoutineDef, test_return_float,
[Exit]
, // args
arg, _auto_return
] // end test_return_float


// convert 'return val' to return an automatic value
[RoutineDef, test_return_int,
[Exit]
, // args
arg, _auto_return
] // end test_return_int
2 changes: 1 addition & 1 deletion zbrush.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Most inputs are strings or numbers; here they are specified as str, float or int but in
zbrush they are all ascii strings or 'numbers' unless specified
* there's no unicode nonsense in zbrush, all strings are ascii or utf-8
* references to memeory blocks use the MemBlock type hint
* references to memory blocks use the MemBlock type hint
* references to StrokeData use the StrokeData or MultipleStrokeData type hints

Not all functions in the zscript command list are represented directly as functions. The ones that
Expand Down
Loading