Perhaps the easiest demo to give here is one that is actually in use: using DocStrip and the .dtx format to contain both TeX and Lua code. I will use the 'all-in-one' .dtx format which I use for my own packages: this is optional, but makes it a little easier to write a demonstration.
The key idea here is to alter what is used as a start-comment string, so that LaTeX comments start %% while Lua comments start --. The comment string is stored as \MetaPrefix, and this is included in the pre- and post-amble via an \edef. So what you need to do is \let\MetaPrefix\relax, then define the pre- and post-amble you want, and only then set it to the appropriate strings. There is one set up for LaTeX: \DoubleperCent. For Lua, it's easy enough to type things in directly.
% \iffalse meta-comment
%<*internal>
\iffalse
%</internal>
%<*readme>
Some information here, perhaps :-)
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\let\MetaPrefix\relax
\preamble
Some preamble text
\endpreamble
\postamble
Some postamble text
\endpostamble
\def\MetaPrefix{-- }
\generate{\file{\jobname.lua}{\from{\jobname.dtx}{lua}}}
\let\MetaPrefix\DoubleperCent
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{latex}}}
%</install>
%<install>\endbatchfile
%<*internal>
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{install}}}
\nopreamble\nopostamble
\usedir{doc/latex/siunitx}
\generate{\file{README.txt}{\from{\jobname.dtx}{readme}}}
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%</internal>
%<*driver>
\documentclass{ltxdoc}
%\DisableImplementation
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \begin{macrocode}
%<*lua>
demo = { }
demo.module = { name = "demo" }
%</lua>
% \end{macrocode}
%
% \begin{macrocode}
%<*latex>
\def\filename{demo}
%</latex>
% \end{macrocode}
If you run tex <filename>.dtx, you will extract out the .lua and .sty files from the above, and can then see that the extraction has worked as required. Running latex <filename>.dtx will also create a .ins file, whcih you might want to use separately. That I know of, multi-line comments are not possible with DocStrip, so you have to use the single-line comment method for the target language.