Skip to content
Open
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
Binary file modified plugins/xtlua/64/lin.xpl
Binary file not shown.
Binary file modified plugins/xtlua/64/mac.xpl
Binary file not shown.
Binary file modified plugins/xtlua/64/win.xpl
Binary file not shown.
36 changes: 21 additions & 15 deletions plugins/xtlua/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function wrap_dref_any_deferred(in_dref)
if self.arr ~= nil then
return self.arr
end
t = XTLuaGetDataRefType(self.dref)
t = XLuaGetDataRefType(self.dref)
b = string.find(t,"%[")
if b ~= nil then
dim = tonumber(string.sub(t,b+1,-2))
Expand All @@ -133,7 +133,7 @@ function wrap_dref_any_deferred(in_dref)
if self.arr ~= nil then
return self.arr
end
t = XTLuaGetDataRefType(self.dref)
t = XLuaGetDataRefType(self.dref)
if t == "string" then
return XTLuaSetString(self.dref,v)
elseif t == "number" then
Expand Down Expand Up @@ -168,12 +168,12 @@ end

function find_dataref(name)
dref = XTLuaFindDataRef(name)
t = XTLuaGetDataRefType(dref)
t = XLuaGetDataRefType(dref)
return wrap_dref_any(dref,t)
end

function create_dataref(name,type,notifier)
error("create_dataref unsupported - use init script")
error("create_dataref unsupported - use xLua")
--[[if notifier == nil then
dref = XLuaCreateDataRef(name,type,"no",nil)
else
Expand All @@ -191,7 +191,7 @@ function make_command_obj(in_cmd, in_name)
return {
start = function(self)
if self.cmd == nil then
self.cmd = XTLuaFindCommand(self.name)
self.cmd = XLuaFindCommand(self.name)
if self.cmd == nil then
error("Unable to find command:"..name)
end
Expand All @@ -200,7 +200,7 @@ function make_command_obj(in_cmd, in_name)
end,
stop = function(self)
if self.cmd == nil then
self.cmd = XTLuaFindCommand(self.name)
self.cmd = XLuaFindCommand(self.name)
if self.cmd == nil then
error("Unable to find command:"..name)
end
Expand All @@ -209,7 +209,7 @@ function make_command_obj(in_cmd, in_name)
end,
once = function(self)
if self.cmd == nil then
self.cmd = XTLuaFindCommand(self.name)
self.cmd = XLuaFindCommand(self.name)
if self.cmd == nil then
error("Unable to find command:"..name)
end
Expand All @@ -222,19 +222,25 @@ function make_command_obj(in_cmd, in_name)
end

function find_command(name)
c = XTLuaFindCommand(name)
c = XLuaFindCommand(name)
return make_command_obj(c,name)
end

function create_command(name,desc,handler)
c = XLuaCreateCommand(name,desc)
XTLuaReplaceCommand(c,handler)
return make_command_obj(c)
end

function replace_command(name, func)
c = XTLuaFindCommand(name)
c = XLuaFindCommand(name)
XTLuaReplaceCommand(c,func)
return make_command_obj(c)
end

function wrap_command(name, before, after)
c = XTLuaFindCommand(name)
XTLuaWrapCommand(c,before,after)
c = XLuaFindCommand(name)
XLuaWrapCommand(c,before,after)
return make_command_obj(c)
end

Expand All @@ -245,16 +251,16 @@ end
function run_timer(func,delay,rep)
tobj = all_timers[func]
if tobj == nil then
tobj = XTLuaCreateTimer(func)
tobj = XLuaCreateTimer(func)
all_timers[func] = tobj
end
XTLuaRunTimer(tobj,delay,rep)
XLuaRunTimer(tobj,delay,rep)
end

function stop_timer(func)
tobj = all_timers[func]
if tobj ~= nil then
XTLuaRunTimer(tobj, -1.0, -1.0)
XLuaRunTimer(tobj, -1.0, -1.0)
end
end

Expand All @@ -263,7 +269,7 @@ function is_timer_scheduled(func)
if tobj == nil then
return false
end
return XTLuaIsTimerScheduled(tobj)
return XLuaIsTimerScheduled(tobj)
end

function run_at_interval(func, interval)
Expand Down
33 changes: 24 additions & 9 deletions plugins/xtlua/init/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,34 +172,30 @@ end
--------------------------------------------------------------------------------

function make_command_obj(in_cmd, in_name)
print("make_command_obj ")
return {
start = function(self)

if self.cmd == nil then
self.cmd = XLuaFindCommand(self.name)
if self.cmd == nil then
error("Unable to find command:"..self.name)
error("Unable to find command:"..name)
end
end
XLuaCommandStart(self.cmd)
end,
stop = function(self)

if self.cmd == nil then
self.cmd = XLuaFindCommand(self.name)
if self.cmd == nil then
error("Unable to find command:"..self.name)
error("Unable to find command:"..name)
end
end
XLuaCommandStop(self.cmd)
end,
once = function(self)

if self.cmd == nil then
self.cmd = XLuaFindCommand(self.name)
if self.cmd == nil then
error("Unable to find command:"..self.name)
error("Unable to find command:"..name)
end
end
XLuaCommandOnce(self.cmd)
Expand Down Expand Up @@ -362,15 +358,16 @@ function namespace_write(table, key, value)
--print("Namespace write of "..key)
ftable = rawget(table,'functions')
vtable = rawget(table,'values')

rkeys = rawget(table,'raw_table_keys')

func = ftable[key]
if func ~= nil then
func.__set(func,value)
else
if seems_like_prop(value) then
ftable[key] = value
else
if not seems_like_object(value) and type(value) == "table" and getmetatable(value) == nil then
if not seems_like_object(value) and type(value) == "table" and getmetatable(value) == nil and rkeys[key] == nil then
--print("Bare table wrap for "..key)
v = {
functions = {},
Expand Down Expand Up @@ -415,6 +412,7 @@ function create_namespace()
ret = {
functions = {},
values = {},
raw_table_keys = {},
create_prop = function(self,name, func)
self.functions[name] = func
end,
Expand Down Expand Up @@ -443,6 +441,21 @@ function get_run_file_in_namespace(ns)
end
end

-- Built in custom closure to build _real_ tables.
function get_real_table_in_namespace(ns)
return function(key,real_table)
vtable = rawget(ns,'values')
vtable[key] = real_table
end
end

function get_raw_table_in_namespace(ns)
return function(key)
rkeys = rawget(ns,'raw_table_keys')
rkeys[key] = true
end
end

--------------------------------------------------------------------------------

function run_module_in_namespace(fn)
Expand All @@ -465,6 +478,8 @@ function run_module_in_namespace(fn)
n.run_after_time = run_after_time
n.run_at_interval = run_at_interval
n.dofile = get_run_file_in_namespace(n)
n.real_table = get_real_table_in_namespace(n)
n.raw_table = get_raw_table_in_namespace(n)

setfenv(fn,n)
fn()
Expand Down