Created
June 15, 2017 14:26
-
-
Save kungfooman/300dced4a72b890f50c6f0ff77679eb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Haii") | |
function log(str) | |
#return ccall(:julia_log, Int, (Cstring,), str) | |
#print(str) | |
leetmenu_log(leetmenu, str); | |
end | |
function pprint(data) | |
return log(string(data) * "\n") | |
end | |
function repl(str, select_from, select_to) | |
if select_from < select_to | |
str = substr(str, select_from, select_to) | |
elseif select_from > select_to | |
str = substr(str, select_to, select_from) | |
end | |
##log("Selectfrom= ($select_from) s_to=($select_to)\n") | |
#try | |
# expr, pos = parse(str, 1) # tbh this makes no sense to me yet... check E:\Julia-0.5.2\share\julia\base\parse.jl line 176 | |
# #pprint(expr) | |
# ret = eval(expr) | |
# pprint(ret) | |
#catch e | |
# pprint(e) | |
#end | |
ret = evalall(str) | |
pprint(ret) | |
end | |
function substr(str, from_, to_) | |
return str[from_+1: to_] | |
end | |
function evalall(str::AbstractString) | |
bstr = String(str) | |
#log(bstr) | |
ret = nothing | |
try | |
ret = ccall(:jl_parse_eval_all, Any, (Cstring, Cstring, Csize_t), "hurr.jl", bstr, sizeof(bstr)) | |
#if raise && isa(ex,Expr) && is(ex.head,:error) | |
# throw(ParseError(ex.args[1])) | |
#end | |
#if ex === () | |
# raise && throw(ParseError("end of input")) | |
# ex = Expr(:error, "end of input") | |
#end | |
catch ex | |
#print("Got error: " * string(ex.error.msg) * "\n") | |
return ex | |
end | |
return ret | |
end | |
# include("repl.jl") | |
# repl("1+2; pprint(11+2)", 0, 3) | |
""" | |
leetmenu_t *leetmenu = &leetmenu_instance; | |
leetmenu_set_visibility(leetmenu, 1); | |
leetmenu_set_window_title(leetmenu, "VisualGraphEditor"); | |
leetmenu_init(leetmenu); | |
while (1) { | |
leetmenu_poll_events(leetmenu); | |
leetmenu_imgui_new_frame(leetmenu); | |
leetmenu_render_gui(leetmenu); | |
leetmenu_swap_buffers(leetmenu); | |
if (leetmenu_should_close(leetmenu)) { | |
return 0; | |
} | |
} | |
""" | |
leetmenu_fromglobal() = ccall(("leetmenu_fromglobal" , "C:\\deepdreamers\\julia\\opsys.dll"), Int64, ()) | |
leetmenu_set_visibility(leetmenu, visible) = ccall(("leetmenu_set_visibility" , "C:\\deepdreamers\\julia\\opsys.dll"), Void, (Int64, Int32), leetmenu, visible) | |
leetmenu_init(leetmenu) = ccall(("leetmenu_init" , "C:\\deepdreamers\\julia\\opsys.dll"), Void, (Int64, ), leetmenu) | |
leetmenu_terminate(leetmenu) = ccall(("leetmenu_terminate" , "C:\\deepdreamers\\julia\\opsys.dll"), Void, (Int64, ), leetmenu) | |
leetmenu_poll_events(leetmenu) = ccall(("leetmenu_poll_events" , "C:\\deepdreamers\\julia\\opsys.dll"), Void, (Int64, ), leetmenu) | |
leetmenu_imgui_new_frame(leetmenu) = ccall(("leetmenu_imgui_new_frame" , "C:\\deepdreamers\\julia\\opsys.dll"), Void, (Int64, ), leetmenu) | |
leetmenu_render_gui(leetmenu) = ccall(("leetmenu_render_gui" , "C:\\deepdreamers\\julia\\opsys.dll"), Void, (Int64, ), leetmenu) | |
leetmenu_swap_buffers(leetmenu) = ccall(("leetmenu_swap_buffers" , "C:\\deepdreamers\\julia\\opsys.dll"), Void, (Int64, ), leetmenu) | |
leetmenu_should_close(leetmenu) = ccall(("leetmenu_should_close" , "C:\\deepdreamers\\julia\\opsys.dll"), Int32, (Int64, ), leetmenu) | |
leetmenu_log(leetmenu, message) = ccall(("leetmenu_log" , "C:\\deepdreamers\\julia\\opsys.dll"), Int32, (Int64, Cstring), leetmenu, message) | |
leetmenu_set_callback_python_eval(leetmenu, callback_python_eval) = ccall(("leetmenu_set_callback_python_eval" , "C:\\deepdreamers\\julia\\opsys.dll"), Void, (Int64, Ptr{Void}), leetmenu, callback_python_eval) | |
# IMPORT_OR_EXPORT void leetmenu_set_callback_python_eval (leetmenu_t *leetmenu, int (*callback_python_eval)(char *code, int select_from, int select_to)); | |
leetmenu = 123 | |
# this is called from inside the .dll, to dynamically evaluate Julia | |
function callback_eval(code::Cstring, select_start::Cint, select_end::Cint) | |
repl(unsafe_string(code), select_start, select_end) | |
return Cint(123) | |
end | |
# | |
callbacky_c = cfunction(callback_eval, Cint, (Cstring, Cint, Cint)) | |
function render() | |
log(".\n") | |
return 123 | |
end | |
function start() | |
leetmenu = leetmenu_fromglobal() | |
print("leetmenu = $leetmenu") | |
leetmenu_set_callback_python_eval(leetmenu, callbacky_c); | |
leetmenu_set_visibility(leetmenu, 1); | |
leetmenu_init(leetmenu); | |
while true | |
leetmenu_poll_events(leetmenu) | |
leetmenu_imgui_new_frame(leetmenu) | |
if render() != 123 | |
log("wow changed!\n") | |
end | |
leetmenu_render_gui(leetmenu) | |
leetmenu_swap_buffers(leetmenu) | |
if leetmenu_should_close(leetmenu) == 1 | |
break | |
end | |
end | |
leetmenu_terminate(leetmenu) | |
end | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment