../
kernel
functions
add
all
apply_delta
assert
atan2
btn
btnp
camera
cd
char
chooser
circ
circfill
clip
cls
color
cos
count
cp
create_delta
create_gui
create_process
cursor
date
del
deli
env
error
exit
fetch
fetch_metadata
fget
fillp
foreach
fset
fstat
fullpath
get_clipboard
get_display
get_draw_target
get_spr
include
input
key
keyp
line
ls
map
max
memcpy
memmap
memset
menuitem
mget
mkdir
mouse
mouselock
mset
music
mv
note
on_event
open
oval
ovalfill
peek
peek2
peek4
peek8
peektext
pget
pid
pod
poke
poke2
poke4
poke8
printh
pset
pwd
readtext
rect
rectfill
rm
rrect
rrectfill
scoresub
send_message
set_clipboard
set_draw_target
set_spr
sfx
sin
socket
split
spr
sspr
stat
stop
store
store_metadata
sub
time
tokenoid
type
unmap
unpod
userdata
vec
vid
window
apply_delta(str0,delta): string
Overview
apply_delta returns str0 with the changes encoded in delta applied upon it. This is used in conjunction with create_delta() which generates the delta between two strings.
Deltas are useful for undo stacks and changes in gamestates being sent across a network; the binary format of the delta includes a few safety features such as crc and length checks to ensure the input and output strings are as expected. The first 4 bytes of the delta string are always dst\0.
Arguments
str0: string
The original string to transform with delta.
delta: string
The encoded changes, generated with create_delta().
Returns
str1: string
Returns str0 with the changes applied from delta, equivalent to str1 of create_delta().
Examples
Sourced from the Picotron Manual
Simple change between two strings
str0="The quick brown fox"
str1="The quick red fox"
delta=create_delta(str0,str1) -- delta that changes the "brown" into "red"
?apply_delta(str0) -- str1
Used with pod() and unpod() to encode the changes between tables.
a = {1,2,3}
b = {1, "banana", 2, 3}
delta = create_delta(pod(a), pod(b)) -- pod is a string, so it can be used to create deltas
b2=apply_delta(pod(a),delta) -- identical to b (as a string)
b=unpod(b2) -- identical to original b