WriteDifferent V1.22 - create your own languages!

information

What exactly is WriteDifferent?

  • WriteDifferent is a module that allows you to create new languages in lua
  • this module is not even close to finished and it won’t have everything you need to add everything you want yet

What can WriteDifferent do so far?

  • WriteDifferent can make functions, libraries, functions that can be added into the libraries, variables, and even more
  • you can create more then one language
  • WriteDifferent allows strings, numbers, booleans, functions, variables, tables, math operations, and nil as arguments

What are the functions for WriteDifferent?

--[[
    Module:AddNewLanguage("LanguageName") returns the language
    Module["LanguageName"]:AddNewLibrary("LibraryName") returns the library
    Module["LanguageName"]:ChangeHolders("StartHolder", "EndHolder") returns the language
    Module["LanguageName"]:ChangeTable("StartHolder", "EndHolder") returns the language
    Module["LanguageName"]:ChangeSeparator("Separator") returns the language
    Module["LanguageName"]:ChangeConnecter("Connecter") returns the language
    Module["LanguageName"]:ChangeVariable("Variable") returns the language
    Module["LanguageName"]:AddNewFunction("FunctionName", function() end) returns the language
    Module["LanguageName"]["Libraries"]["LibraryName"]:AddNewFunction("FunctionName", function() end) returns the library
    Module["LanguageName"]:RunCode([[code]]) returns the language
]]
how to use Language:RunCode
Language:RunCode([[
    local VariableName = 0
    local TableName = {1, 2, 3}
    VariableName = TableName
    
    FunctionName (true, false)
    LibraryName.FunctionName ("yes", "no", VariableName)
]])

"local" can be changed with Language:ChangeVariable
"("..Arguments..")" can be changed with Language:ChangeHolders
"{"..TableValues.."}" can be changed with Language:ChangeTable
"." can be changed with Language:ChangeConnecter
"," can be changed with Language:ChangeSeparator

there is multi line support for functions and tables

example code
local Module = require(7262039707)
local Language = Module:AddNewLanguage("Complex")
local Math = Language:AddNewLibrary("Math")

Language:ChangeHolders("{", "}")
Language:ChangeTable("<", ">")
Language:ChangeSeparator(";")
Language:ChangeConnecter(":")
Language:ChangeVariable("New")

Language:AddNewFunction("PrintLine", print)

Language:AddNewFunction("WarnLine", warn)

Language:AddNewFunction("ErrorLine", error)

Language:AddNewFunction("CheckType", typeof)

Language:AddNewFunction("Sleep", task.wait)

Math:AddNewFunction("RandomInteger", function(Minimum, Maximum)
	if typeof(Minimum) ~= "number" then
		return error("minimum has to be a number")
	end
	if typeof(Maximum) ~= "number" then
		return error("maximum has to be a number")
	end

	return Random.new():NextInteger(Minimum, Maximum)
end)

Math:AddNewFunction("RandomNumber", function(Minimum, Maximum)
	if typeof(Minimum) ~= "number" then
		return error("minimum has to be a number")
	end
	if typeof(Maximum) ~= "number" then
		return error("maximum has to be a number")
	end

	return Random.new():NextNumber(Minimum, Maximum)
end)

task.wait(5)

Language:RunCode([[
    New CheckString = CheckType {"this is a string!"}
    New RandomInteger = Math:RandomInteger {1; 3}
    New RandomNumber = Math:RandomNumber {1; 3}
    New Table = <1; 2; 3; 4; 5>
    New Test = (((20 / 2)^(100 - 300) % 5) + 5)
    
    PrintLine {Table; Test}
    
    PrintLine {"test"; CheckString}
    WarnLine {"test"; CheckString}
    
    PrintLine {RandomInteger}
    WarnLine {RandomNumber}
    
    PrintLine {Sleep {RandomInteger}}
    WarnLine {Sleep {RandomNumber}}
    
    ErrorLine {"this is a error message!"; 0}
]])

image

you can get the module here or you can require it like this

require(7262039707)

if you need any help at all on why your code isn’t working just tell me, also I am always up to fixing up any problems within the module
the code is far from perfect and can obviously be improved as well, so I will need to optimize the code

anyways enjoy the module!

25 Likes

A good idea for this would be a plugin where you can write this “new” code and it compiles to a proper Luau file.

5 Likes

sounds like a great idea, I would need to learn how to make plugins since I’ve never made any yet, but that’s fine

1 Like

Pretty cool concept. But theres quite a lot of duplicate code blocks in your code, using functions will be better. :+1:

1 Like

Honestly please continue working on this. My reason is this could possible allow Roblox games to have
advanced community mods with programming and the developer of the game can control and limit the power of it to prevent abuse.

Next thing to work on is loops and arrays/tables.

3 Likes

I agree, this concept is really amazing and can make roblox games better.

1 Like

although this would provide a way for the community to create mods for your game it potentially opens up your game to be able to be targeted by more malicious exploits.

1 Like

actually my goal is to clean repeated code, and then I’m adding if, elseif, and else statements
because those are more important then loops right now

also tables are just as important, because you can then be more creative with your code, I also plan to add math operations as well

do you think this can be changed or at least helped to be more safe?

the prevention is down to the game developer tbh - if the community has access to the language they can create exploits with it.

1 Like

Finally, it’s open sourced! Time to rewrite Luau.

I notice there’s a lot of if statements then errors, you can change that like this:
assert(check, "this will error if check is not true")

2 Likes

I personally don’t use assert, mainly because I find if statements more appealing to me, but if it has performance improvements then I’ll use it

1 Like

WriteDifferent V1.05

  • removed a lot of repeated code
  • fixed a minor variable bug
1 Like

What is the purpose of this module? I wouldn’t consider it creating your own languages, just changing the tokens used in the language isn’t really changing much, they are functionally equivalent. Adding new functions doesn’t change the language in any way, all of the same constructs are used.

A better way of stating this would be: Every line must be empty or be an individual statement.

The section is a very brief description of the language, with no specifics. What is the grammar of the language? What is format for string literals or numbers?

When I tried the module, Random(Random(1,1),5) was invalid, but local x = Random(1,1) \n Random(x,5) was valid (Random is just a random number generator). It also seemed to allow " in string literals created with "..."?


All of the self parameters are unused in this module, so the functions don’t need to be passed self (which is done implicitly with :). The self parameters should be removed (they are implicitly added by :).

Looking at the module I noticed some inefficient programming patterns:

Creating new strings is expensive, and this module creates many temporary strings. For instance calling string.gsub just to count occurrences creates an unused string, and building strings by concatenating many times in a loop will create many substrings. Temporary strings should be avoided, for instance using table.concat to combine many strings without creating temporary strings.

Also, every time a function body is encountered, a new function object will be created. By putting function inside of a function, a new function object gets created on every call. This module does this many times, namely for the methods of the Language object. A common Lua idiom is to use metatables for classes, to add methods to every object without creating individual function objects for each object or entries for each method. Because the function objects aren’t specific to each object, they are passed into the method on each call.

1 Like

Creating a new language with a separate syntax wouldn’t be a very useful resource.

But the purpose of this is to have your own language with your own library’s and its own functionality to run code in a controlled way.

Plus custom tokens is always a nice customization feature.

Also in my reply above I say why could this be a very useful resource.

1 Like

I said many many times now, it is far from finished

no a line could sometimes only have spaces which isn’t “empty”, but thanks for the suggestion!

can you send me your code so I can fix this bug, thank you

I use “:” because I don’t want the player to use “.” when using functions

I guess I could use self, but it doesn’t matter much at this moment in time

thanks for the advice

this module is still new so it isn’t perfect

1 Like

self doesn’t need to be provided as an argument, so why provide it? What is wrong with the user using . when calling the methods? If you don’t intend to create new function objects every time, then the common Lua idiom of metatables for methods should be used. I’m not saying to use self, but to either remove self from the parameter list, or to not create individual function objects for every object, which would make the self parameter useful.

Are non line space characters meaningful or not? If they are meaningful then that would make sense, but if they aren’t meaningful then an empty line of just spaces should just be ignored. They would only be considered when delimiting other meaningful constructs (like 2 names delimited by a space).

require(7262039707):AddNewLanguage"":AddNewFunction("Random",math.random):RunCode"Random(Random(1,1),5)"
1 Like

Although it could be difficult, you can make a plugin that has its own mini IDE where you can code the language like you would Lua, instead of typing it in a string

1 Like

no I just meant that a line could be

"                   "

i only said that since you said lines could be empty or an individual statement

now that I think about it, spaces could be considered empty

thanks I will work on fixing this!

A suggestion came across my mind while I was reading the recent posts here:

Allow “plugins” for this module. For example, people can write their own plugins, that have features that the main module doesn’t have yet. For example, if statements, loops, etc.

1 Like