Add a variable to a class instance at runtime: Difference between revisions
Content deleted Content added
Added BBC BASIC |
|||
Line 71:
<lang AutoHotkey>e := {}
e.foo := 1 </lang>
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
It's not really intended that you should do this, but if you must you can:
<lang bbcbasic> INSTALL @lib$+"CLASSLIB"
REM Create a base class with no members:
DIM class{method}
PROC_class(class{})
REM Instantiate the class:
PROC_new(myobject{}, class{})
REM Add a member at run-time:
member$ = "mymember#"
PROCaddmember(myobject{}, member$, 8)
REM Test that the member can be accessed:
PROCassign("myobject." + member$, "PI")
PRINT EVAL("myobject." + member$)
END
DEF PROCaddmember(RETURN obj{}, mem$, size%)
LOCAL D%, F%, P%
DIM D% DIM(obj{}) + size% - 1, F% LEN(mem$) + 8
P% = !^obj{} + 4
WHILE !P% : P% = !P% : ENDWHILE : !P% = F%
$$(F%+4) = mem$ : F%!(LEN(mem$) + 5) = DIM(obj{})
!(^obj{} + 4) = D%
ENDPROC
DEF PROCassign(v$, n$)
IF EVAL("FNassign(" + v$ + "," + n$ + ")")
ENDPROC
DEF FNassign(RETURN n, v) : n = v : = 0</lang>
=={{header|Bracmat}}==
|