mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 11:25:29 -04:00
Rename the state
helper function to storage
This commit is contained in:
parent
ebf6221876
commit
f116e2f1d0
@ -50,7 +50,7 @@ class Plugin
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
struct State
|
struct Storage
|
||||||
@hash = {} of String => String
|
@hash = {} of String => String
|
||||||
|
|
||||||
def initialize(@path : String)
|
def initialize(@path : String)
|
||||||
@ -81,7 +81,7 @@ class Plugin
|
|||||||
@info : Info?
|
@info : Info?
|
||||||
|
|
||||||
getter js_path = ""
|
getter js_path = ""
|
||||||
getter state_path = ""
|
getter storage_path = ""
|
||||||
|
|
||||||
def self.build_info_ary
|
def self.build_info_ary
|
||||||
return unless @@info_ary.empty?
|
return unless @@info_ary.empty?
|
||||||
@ -128,7 +128,7 @@ class Plugin
|
|||||||
end
|
end
|
||||||
|
|
||||||
@js_path = File.join info.dir, "main.js"
|
@js_path = File.join info.dir, "main.js"
|
||||||
@state_path = File.join info.dir, "state.json"
|
@storage_path = File.join info.dir, "storage.json"
|
||||||
|
|
||||||
unless File.exists? @js_path
|
unless File.exists? @js_path
|
||||||
raise Error.new "Plugin script not found at #{@js_path}"
|
raise Error.new "Plugin script not found at #{@js_path}"
|
||||||
@ -137,11 +137,11 @@ class Plugin
|
|||||||
@rt = Duktape::Runtime.new do |sbx|
|
@rt = Duktape::Runtime.new do |sbx|
|
||||||
sbx.push_global_object
|
sbx.push_global_object
|
||||||
|
|
||||||
sbx.push_pointer @state_path.as(Void*)
|
sbx.push_pointer @storage_path.as(Void*)
|
||||||
path = sbx.require_pointer(-1).as String
|
path = sbx.require_pointer(-1).as String
|
||||||
sbx.pop
|
sbx.pop
|
||||||
sbx.push_string path
|
sbx.push_string path
|
||||||
sbx.put_prop_string -2, "state_path"
|
sbx.put_prop_string -2, "storage_path"
|
||||||
|
|
||||||
def_helper_functions sbx
|
def_helper_functions sbx
|
||||||
end
|
end
|
||||||
@ -303,17 +303,17 @@ class Plugin
|
|||||||
env = Duktape::Sandbox.new ptr
|
env = Duktape::Sandbox.new ptr
|
||||||
key = env.require_string 0
|
key = env.require_string 0
|
||||||
|
|
||||||
env.get_global_string "state_path"
|
env.get_global_string "storage_path"
|
||||||
state_path = env.require_string -1
|
storage_path = env.require_string -1
|
||||||
env.pop
|
env.pop
|
||||||
state = State.new state_path
|
storage = Storage.new storage_path
|
||||||
|
|
||||||
if env.get_top == 2
|
if env.get_top == 2
|
||||||
val = env.require_string 1
|
val = env.require_string 1
|
||||||
state[key] = val
|
storage[key] = val
|
||||||
state.save
|
storage.save
|
||||||
else
|
else
|
||||||
val = state[key]?
|
val = storage[key]?
|
||||||
if val
|
if val
|
||||||
env.push_string val
|
env.push_string val
|
||||||
else
|
else
|
||||||
@ -323,7 +323,7 @@ class Plugin
|
|||||||
|
|
||||||
env.call_success
|
env.call_success
|
||||||
end
|
end
|
||||||
sbx.put_prop_string -2, "state"
|
sbx.put_prop_string -2, "storage"
|
||||||
|
|
||||||
sbx.put_prop_string -2, "mango"
|
sbx.put_prop_string -2, "mango"
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user