Skip to content

Commit ef80fe9

Browse files
authored
Add ability to have multiple source files in createSent for starfall_… (#1992)
* Add ability to have multiple source files in createSent for starfall_processor * fixes * fix
1 parent a6e09d5 commit ef80fe9

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

lua/starfall/instance.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ function SF.Instance:runExternal(func, ...)
531531
self:pushCpuCheck()
532532
local ok, err = xpcall(func, debug.traceback, ...)
533533
self:popCpuCheck()
534-
if ok then return err else ErrorNoHalt(err) end
534+
return ok, err
535535
end
536536

537537
local function xpcall_callback(err)

lua/starfall/libs_sv/prop.lua

+1-9
Original file line numberDiff line numberDiff line change
@@ -605,14 +605,7 @@ function props_library.createSent(pos, ang, class, frozen, data)
605605
enttbl.Pos = pos
606606
enttbl.Angle = ang
607607

608-
-- Temporarily disable SF runningOps, because SENT like E2 rely on string metatable methods!
609-
-- E2 calls string:find with colon sugar syntax, this means E2 code ended up calling into string __index metamethod (see sflib.lua where SF does metatable patching).
610-
-- In case of E2, it usually results in obscure errors being thrown (such as "error in error handling", random things being nil, etc).
611-
local runningOpsBackup = SF.runningOps
612-
SF.runningOps = nil
613-
614-
-- Better be safe, pcall this to ensure we continue running our code, in case these external functions cause an error...
615-
local isOk, errorMsg = pcall(function()
608+
local isOk, errorMsg = instance:runExternal(function()
616609
if sent2._preFactory then
617610
sent2._preFactory(ply, enttbl)
618611
end
@@ -638,7 +631,6 @@ function props_library.createSent(pos, ang, class, frozen, data)
638631
end
639632
end)
640633

641-
SF.runningOps = runningOpsBackup -- Restore back runningOps to SF control, and everything is fine :)
642634
if not isOk then
643635
if IsValid(entity) then
644636
entity:Remove()

lua/starfall/libs_sv/prop_sent.lua

+13-4
Original file line numberDiff line numberDiff line change
@@ -1011,13 +1011,23 @@ registerSent("gmod_wire_expression2", {
10111011
["inc_files"] = {TYPE_TABLE, {}},
10121012
}
10131013
})
1014+
end
1015+
end)
10141016

10151017
registerSent("starfall_processor", {
10161018
_preFactory = function(ply, self)
10171019
end,
10181020
_postFactory = function( ply, self, enttbl )
1021+
local Files = {
1022+
["main"] = enttbl.Code
1023+
}
1024+
for path, code in pairs(enttbl.Files) do
1025+
checkluatype(path, TYPE_STRING, 3, "Parameter: Files[" .. path .. "]")
1026+
checkluatype(code, TYPE_STRING, 3, "Parameter: Files[" .. path .. "]")
1027+
Files[path] = code
1028+
end
10191029
local Data = {
1020-
["files"] = {["main"] = enttbl.Code},
1030+
["files"] = Files,
10211031
["mainfile"] = "main",
10221032
["owner"] = ply
10231033
}
@@ -1026,12 +1036,10 @@ registerSent("starfall_processor", {
10261036
{
10271037
["Model"] = {TYPE_STRING, "models/spacecode/sfchip_medium.mdl"},
10281038
["Code"] = {TYPE_STRING},
1039+
["Files"] = {TYPE_TABLE, {}}
10291040
}
10301041
})
10311042

1032-
end
1033-
end)
1034-
10351043
function SF.PrintCustomSENTDocs()
10361044
local tostr = {
10371045
string = function(x) return "\"" .. x .. "\"" end,
@@ -1330,6 +1338,7 @@ return function() end
13301338
-- > starfall_processor
13311339
-- string Model = "models/spacecode/sfchip_medium.mdl"
13321340
-- string Code
1341+
-- table Files = {main = Code}
13331342
--
13341343
-- > gmod_wire_extbus
13351344
-- string Model = "models/jaanus/wiretool/wiretool_gate.mdl"

lua/starfall/libs_sv/wire.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,8 @@ end
648648
local function readCell(ent, k)
649649
checkpermission(instance, nil, "wire.wirelink.read")
650650
local ReadCell = Ent_GetTable(ent).ReadCell or SF.Throw("Entity does not have ReadCell capability", 3)
651-
return tonumber(instance:runExternal(ReadCell, ent, k))
651+
local ok, n = instance:runExternal(ReadCell, ent, k)
652+
return ok and tonumber(n) or 0
652653
end
653654

654655
--- Sets the value of an entity's input, triggering it as well

0 commit comments

Comments
 (0)